-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.js
executable file
·68 lines (60 loc) · 1.55 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
#!/usr/bin/node
/*
esbuild configuration.
Usage:
yarn run esbuild:build
yarn run esbuild:watch
*/
const esbuild = require('esbuild');
const copyStaticFiles = require('esbuild-copy-static-files');
const args = process.argv.slice(2);
const mode = args.includes('--watch') ? 'watch' : 'build';
const outputDir = process.env.DIST_DIR || `${__dirname}/ohmyadmin/statics`;
const plugins = [
copyStaticFiles({
src: './assets/static',
dest: outputDir,
dereference: true,
errorOnExist: false,
preserveTimestamps: true,
recursive: true,
}),
];
async function main() {
const context = await esbuild.context({
entryPoints: [
`${__dirname}/assets/main.ts`,
// `${__dirname}/assets/js/**/*.ts`,
// `${__dirname}/assets/components/**/*.ts`,
],
outdir: outputDir,
target: 'esnext',
format: 'esm',
bundle: true,
chunkNames: '[name]-[hash]',
sourcemap: true,
define: {},
treeShaking: true,
loader: {
'.png': 'dataurl',
'.jpg': 'file',
'.jpeg': 'file',
'.svg': 'file',
'.gif': 'file',
},
plugins: plugins,
minify: mode == 'build',
external: ['/fonts/*', '/images/*'],
logLevel: 'debug',
});
if (mode == 'watch') {
await context.watch();
} else {
await context.rebuild();
await context.dispose();
}
}
main().catch((e) => {
console.error(e);
process.exit(1);
});