-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.js
64 lines (55 loc) · 1.71 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
const fs = require('node:fs').promises;
async function build(options) {
options.define || (options.define = {})
const ctx = await require('esbuild').context({
logLevel: process.argv.includes('--watch') ? 'info' : 'warning',
write: false,
...options,
});
const result = await ctx.rebuild();
if (result.outputFiles) {
await Promise.all(result.outputFiles.map((f) => fs.writeFile(f.path, f.contents)))
.then(() => {
console.log(`✨ Build '${options.outfile}' succeeded.`)
});
}
if (process.argv.includes('--watch')) {
// Enable watch
console.log(`👀 Watching '${options.outfile}'..`);
ctx.watch();
}
return ctx;
}
const pkgs = require('./package.json');
const modules = {
'alpinejs': {
'define': {
'ALPINE_VERSION': `'${pkgs.dependencies['alpinejs'].replace(/[\^]/, '')}'`
},
'entryPoints': [ 'src/index.js' ],
},
'@vue/reactivity': {
'entryPoints': [ 'dist/reactivity.esm-browser.js' ],
},
};
const isProduction = process.argv.includes('--production');
const externals = Object.keys(modules);
const promises = [];
for (const k in modules) {
const module = modules[k]
const p = build(Object.assign(module, {
format: 'esm',
bundle: true,
external: externals,
minify: isProduction,
sourcemap: !isProduction,
outfile: `mod/${k}/index${isProduction ? '.min' : ''}.js`,
entryPoints: module.entryPoints.map((ep) => `node_modules/${k}/${ep}`),
}));
promises.push(p);
}
Promise.all(promises)
.then((results) => {
results.forEach((ctx) => ctx.dispose());
console.log('👋🏻 Bye..')
})