forked from civ-clone/electron-renderer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathesbuild.js
63 lines (55 loc) · 1.26 KB
/
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
(async () => {
const { build } = require('esbuild'),
{ sassPlugin } = require('esbuild-sass-plugin'),
buildOptions = {
entryPoints: [
'src/css/app.scss',
'src/js/backend.ts',
'src/js/frontend.ts'
],
bundle: true,
keepNames: true,
minify: true,
sourcemap: true,
watch: false,
outdir: 'dist',
plugins: [
sassPlugin(),
],
loader: {
'.build': 'text',
'.jpg': 'file',
'.png': 'dataurl',
'.svg': 'dataurl'
},
entryNames: '[name]',
};
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');
},
};
}
if (arg === 'dev') {
buildOptions.minify = false;
}
});
process.stdout.write(`Building... `);
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);
});
})();