-
Notifications
You must be signed in to change notification settings - Fork 44
/
bundle.js
56 lines (50 loc) · 1.36 KB
/
bundle.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
44
45
46
47
48
49
50
51
52
53
54
55
56
const { build } = require('esbuild');
const rimraf = require('rimraf');
const plugin = require('node-stdlib-browser/helpers/esbuild/plugin');
const stdLibBrowser = require('node-stdlib-browser');
const fs = require('fs');
const path = require('path');
const clean = async () => {
return new Promise((resolve) => {
rimraf('./bundles', () => resolve());
});
};
const runBuild = async () => {
await clean();
const buildConfig = {
entryPoints: ['./src/index.ts'],
bundle: true,
platform: 'browser',
target: ['esnext'],
format: 'esm',
globalName: 'warp',
inject: [require.resolve('node-stdlib-browser/helpers/esbuild/shim')],
plugins: [plugin(stdLibBrowser)]
};
console.log('Building web bundle esm.');
const result = await build({
...buildConfig,
minify: true,
// metafile: true,
outfile: './bundles/web.bundle.min.js'
}).catch((e) => {
console.log(e);
process.exit(1);
});
// fs.writeFileSync(path.join(__dirname, 'metafile.json'), JSON.stringify(result.metafile));
console.log('Building web bundle iife.');
await build({
...buildConfig,
minify: true,
target: ['esnext'],
format: 'iife',
outfile: './bundles/web.iife.bundle.min.js'
}).catch((e) => {
console.log(e);
process.exit(1);
});
};
runBuild().finally(() => {
console.log('Build done.');
});
module.exports = runBuild;