-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbundle.js
More file actions
48 lines (43 loc) · 1.16 KB
/
bundle.js
File metadata and controls
48 lines (43 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// @ts-check
/** @typedef {import('esbuild').BuildOptions} BuildOptions */
const { build } = require('esbuild');
const { nodeExternalsPlugin } = require('esbuild-node-externals');
const { Generator } = require('npm-dts');
const packageJSON = require('./package.json');
const optionDTS = process.argv.includes('--dts')
const optionSourceMap = process.argv.includes('--source-map')
/** @type {BuildOptions} */
const commonConfig = {
target: 'ES2020',
platform: 'node',
entryPoints: [packageJSON.source],
bundle: true,
minify: false,
sourcemap: optionSourceMap,
plugins: [nodeExternalsPlugin()],
};
/** @type {BuildOptions[]} */
const configurations = [
{
...commonConfig,
outfile: packageJSON.module,
format: 'esm',
},
{
...commonConfig,
outfile: packageJSON.main,
format: 'cjs',
},
];
const dtsGenerator = new Generator({
entry: packageJSON.source,
output: packageJSON.types,
});
(async () => {
await Promise.all(
[
...configurations.map((config) => build(config)),
(optionDTS ? dtsGenerator.generate() : Promise.resolve()),
]
);
})();