-
Notifications
You must be signed in to change notification settings - Fork 2
/
esbuild.js
44 lines (38 loc) · 957 Bytes
/
esbuild.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
const { sassPlugin } = require('esbuild-sass-plugin'),
{ Prettier } = require('esbuild-plugin-prettier'),
esbuild = require('esbuild'),
buildOptions = {
entryPoints: ['src/js/app.ts', 'src/css/app.scss'],
bundle: true,
minify: true,
sourcemap: true,
watch: false,
outdir: 'dist',
plugins: [sassPlugin(), new Prettier()],
};
process.argv.forEach((arg) => {
if (arg === 'watch') {
buildOptions.watch = {
onRebuild(error, result) {
if (error) {
console.log('\x1b[31mError rebuilding:\x1b[0m');
console.error(error);
return;
}
console.log('\x1b[32mRebuilt.\x1b[0m');
},
};
}
});
process.stdout.write(`Building... `);
esbuild
.build(buildOptions)
.then(() => {
console.log('\x1b[32mdone.\x1b[0m');
})
.catch((e) => {
console.log(`\x1b[31mfailed.\x1b[0m`);
console.log('');
console.error(e);
process.exit(1);
});