-
Notifications
You must be signed in to change notification settings - Fork 1
/
esbuild.dev.ts
69 lines (59 loc) · 1.89 KB
/
esbuild.dev.ts
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import { build, serve, BuildOptions } from 'esbuild';
import { NodeModulesPolyfillPlugin } from '@esbuild-plugins/node-modules-polyfill';
import { NodeGlobalsPolyfillPlugin } from '@esbuild-plugins/node-globals-polyfill';
const buildOptsNode: BuildOptions = {
entryPoints: ['./src/index.ts'],
outfile: './dist/node/NodeFlow.js',
platform: 'node',
target: ['es2018'],
format: 'cjs',
bundle: true,
sourcemap: true,
minify: false,
treeShaking: false,
plugins: [
]
};
const buildOptsWeb: BuildOptions = {
entryPoints: ['./src/index.ts'],
// inject: [],
outfile: './dist/web/NodeFlow.js',
// external: [],
platform: 'browser',
target: ['esNext'],
// format: 'cjs',
bundle: true,
sourcemap: true,
minify: true,
treeShaking: true,
plugins: [
// NodeModulesPolyfillPlugin(),
// NodeGlobalsPolyfillPlugin({
// process: true,
// }),
],
};
const serveOpts = {
servedir: './'
};
const flags = process.argv.filter(arg => /--[^=].*/.test(arg));
const enableWatch = (flags.includes('--watch'));
if (enableWatch) {
buildOptsNode.watch = {
onRebuild: (error, result) => {
if (error) { console.error('watch node development build failed:', error); }
else { console.log('watch node development build succeeded:', result); }
}
};
buildOptsWeb.watch = {
onRebuild: (error, result) => {
if (error) { console.error('watch web development build failed:', error); }
else { console.log('watch web development build succeeded:', result); }
}
};
serve(serveOpts, {}).then((result) => {
console.log(`serving extension from "${serveOpts.servedir}" at "http://${result.host}:${result.port}"`);
});
}
build(buildOptsNode).then(() => enableWatch ? console.log("watching node development build...") : null);
build(buildOptsWeb).then(() => enableWatch ? console.log("watching web development build...") : null);