/
build.js
69 lines (61 loc) · 1.5 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
69
const path = require("path");
const esbuild = require("esbuild");
const stylePlugin = require("esbuild-style-plugin");
const postcssImport = require("postcss-import");
const tailwind = require("tailwindcss");
const autoprefixer = require("autoprefixer");
const args = process.argv.slice(2);
const watch = args.includes("--watch");
const deploy = args.includes("--deploy");
const outDir = path.resolve(
__dirname,
deploy ? "../static/assets" : "../tmp/static_dev/assets"
);
async function main() {
await esbuild.build({
entryPoints: [
"./node_modules/monaco-editor/esm/vs/language/json/json.worker.js",
"./node_modules/monaco-editor/esm/vs/editor/editor.worker.js",
],
outdir: outDir,
bundle: true,
target: "es2017",
format: "iife",
minify: deploy,
});
const ctx = await esbuild.context({
entryPoints: ["js/app.js"],
outdir: outDir,
bundle: true,
splitting: true,
target: "es2017",
format: "esm",
minify: deploy,
sourcemap: deploy ? undefined : "linked",
plugins: [
stylePlugin({
postcss: {
plugins: [postcssImport, tailwind, autoprefixer],
},
}),
],
loader: {
".ttf": "file",
".woff": "file",
".woff2": "file",
".eot": "file",
".svg": "file",
},
});
if (watch) {
await ctx.watch();
process.stdin.on("close", () => {
process.exit(0);
});
process.stdin.resume();
} else {
await ctx.rebuild();
process.exit(0);
}
}
main();