-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
70 lines (60 loc) · 1.49 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
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
70
const esbuild = require('esbuild');
// copied from https://github.com/yanm1ng/esbuild-plugin-external-global
const handle_external_globals = (externals) => {
const name = 'globals';
return {
name,
setup(build) {
build.onResolve({ filter: new RegExp('^(' + Object.keys(externals).join('|') + ')$') }, (args) => ({
path: args.path,
namespace: name,
}));
build.onLoad({ filter: /.*/, namespace: name }, (args) => {
return { contents: `module.exports = ${externals[args.path]}` };
});
},
};
};
async function main() {
const name = 'chartjs-scale-timestack';
const replace_globals = handle_external_globals({
'chart.js': 'Chart',
luxon: 'luxon',
});
const common = {
packages: 'external',
bundle: true,
platform: 'browser',
target: ['es2020', 'edge88', 'firefox78', 'chrome87', 'safari14'],
entryPoints: ['src/index.ts'],
};
const esm = {
...common,
format: 'esm',
outfile: `dist/index.esm.js`,
};
const cjs = {
...common,
format: 'cjs',
outfile: `dist/index.cjs.js`,
};
const iife = {
...common,
format: 'iife',
outfile: `dist/${name}.js`,
globalName: '_timestack',
plugins: [replace_globals],
};
const iife_min = {
...common,
format: 'iife',
minify: true,
outfile: `dist/${name}.min.js`,
globalName: '_timestack',
plugins: [replace_globals],
};
for (const cfg of [esm, cjs, iife, iife_min]) {
esbuild.build(cfg);
}
}
main();