-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.js
43 lines (40 loc) · 1.01 KB
/
build.js
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
const esbuild = require('esbuild')
const { nodeExternalsPlugin } = require('esbuild-node-externals')
const COMMON = {
entryPoints: ['./src/index.ts'],
minify: false,
sourcemap: true,
platform: 'node',
target: 'node14',
bundle: true,
plugins: [nodeExternalsPlugin()],
}
const buildOptions =[
{
...COMMON,
format: 'cjs',
target: 'es2015',
outfile: 'dist/index.node.js',
},
{
...COMMON,
format: 'esm',
target: 'es2017',
outfile: 'dist/index.node.mjs',
banner:{
js: `
import { fileURLToPath } from 'url';
import path from 'path';
import { createRequire as topLevelCreateRequire } from 'module';
const require = topLevelCreateRequire(import.meta.url);
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
`
},
},
]
buildOptions.forEach(options => {
esbuild.build(options)
.then(() => console.log(`${options.format} Built Successfully!`))
.catch(() => process.exit(1))
})