-
Notifications
You must be signed in to change notification settings - Fork 0
/
esbuild-script.js
63 lines (55 loc) · 1.57 KB
/
esbuild-script.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
const esbuild = require('esbuild');
const copyStaticFiles = require('esbuild-copy-static-files');
const postCssPlugin = require('esbuild-style-plugin');
const config = {
entryPoints: ['./src/app/index.web.tsx', './src/app/service-worker.ts'],
outdir: './build',
bundle: true,
define: {},
// plugins
plugins: [
copyStaticFiles({
src: './static',
dest: './build',
dereference: true,
errorOnExist: false,
recursive: true,
}),
postCssPlugin({
postcss: {
plugins: [require('tailwindcss'), require('autoprefixer')],
},
}),
],
};
const defineProductionFlag = (flag) =>
(config.define.IS_PRODUCTION = String(flag));
async function buildProd() {
console.log('Executing prod build');
defineProductionFlag(true);
config.minify = true;
// config.format = 'esm'; // produces invalid build? some module imports or smth. 'type="module"' in <script>?
config.sourcemap = true;
config.target = 'chrome100,firefox100,safari15'.split(',');
await esbuild.build(config);
console.log(
`Build finished sucesfully. The files are in '${config.outdir}' directory.`
);
}
async function startDev() {
console.log('Starting dev compile process');
defineProductionFlag(false);
const ctx = await esbuild.context(config);
await ctx.watch();
console.log(`Done. Watching for code changes...`);
let { host, port } = await ctx.serve({
servedir: 'build',
});
console.log(`Serve: http://localhost:${port}/`);
}
const isDev = process.argv.some((e) => e == '--dev');
if (isDev) {
startDev();
} else {
buildProd();
}