-
Notifications
You must be signed in to change notification settings - Fork 18
/
esbuild.js
67 lines (61 loc) · 1.47 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
64
65
66
67
const { build } = require('esbuild'),
{ sassPlugin } = require('esbuild-sass-plugin'),
{ copy } = require('esbuild-plugin-copy'),
buildOptions = {
entryPoints: ['src/webdav.ts'],
bundle: true,
minify: true,
sourcemap: true,
watch: false,
outdir: 'dist',
plugins: [
sassPlugin(),
copy({
resolveFrom: 'cwd',
assets: [
{
from: ['./dist/webdav.js'],
to: ['./src/webdav-min.js'],
},
{
from: ['./dist/webdav.js.map'],
to: ['./src/webdav.js.map'],
},
{
from: ['./dist/webdav.css'],
to: ['./assets/css/style.css', './assets/css/style-min.css'],
},
{
from: ['./dist/webdav.css.map'],
to: ['./assets/css/webdav.css.map'],
},
],
}),
],
entryNames: '[dir]/[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');
},
};
}
});
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);
});