|
| 1 | +import * as path from 'node:path'; |
| 2 | + |
1 | 3 | import commonjs from '@rollup/plugin-commonjs'; |
| 4 | +import inject from '@rollup/plugin-inject'; |
2 | 5 | import json from '@rollup/plugin-json'; |
3 | 6 | import nodeResolve from '@rollup/plugin-node-resolve'; |
4 | | -import { nodeExternals } from 'rollup-plugin-node-externals'; |
5 | 7 | import { dts } from 'rollup-plugin-dts'; |
6 | 8 |
|
| 9 | +function defineBuild(isNode) { |
| 10 | + const suffix = isNode ? '.node' : ''; |
| 11 | + |
| 12 | + return { |
| 13 | + input: 'lib/index.js', |
| 14 | + output: [ |
| 15 | + { |
| 16 | + file: `dist/bundle${suffix}.mjs`, |
| 17 | + format: 'esm', |
| 18 | + sourcemap: true |
| 19 | + }, |
| 20 | + { |
| 21 | + file: `dist/bundle${suffix}.cjs`, |
| 22 | + format: 'cjs', |
| 23 | + sourcemap: true |
| 24 | + } |
| 25 | + ], |
| 26 | + plugins: [ |
| 27 | + [ |
| 28 | + json(), |
| 29 | + nodeResolve({ preferBuiltins: false, browser: true }), |
| 30 | + commonjs({}), |
| 31 | + inject({ |
| 32 | + Buffer: isNode ? 'node:buffer' : path.resolve('lib/buffer.js') |
| 33 | + }) |
| 34 | + ] |
| 35 | + ], |
| 36 | + external: ['async-mutex', 'bson', 'buffer/', 'event-iterator'] |
| 37 | + }; |
| 38 | +} |
| 39 | + |
7 | 40 | /** |
8 | 41 | * @returns {import('rollup').RollupOptions} |
9 | 42 | */ |
10 | | -export default (commandLineArgs) => { |
| 43 | +export default () => { |
11 | 44 | return [ |
12 | | - { |
13 | | - input: 'lib/index.js', |
14 | | - output: [ |
15 | | - { |
16 | | - file: 'dist/bundle.mjs', |
17 | | - format: 'esm', |
18 | | - sourcemap: true |
19 | | - }, |
20 | | - { |
21 | | - file: 'dist/bundle.cjs', |
22 | | - format: 'cjs', |
23 | | - sourcemap: true |
24 | | - } |
25 | | - ], |
26 | | - plugins: [json(), nodeResolve({ preferBuiltins: false, browser: true }), commonjs({}), nodeExternals()] |
27 | | - }, |
| 45 | + defineBuild(false), |
| 46 | + defineBuild(true), |
28 | 47 | { |
29 | 48 | input: './lib/index.d.ts', |
30 | 49 | output: [{ file: 'dist/index.d.cts', format: 'cjs' }], |
|
0 commit comments