-
Notifications
You must be signed in to change notification settings - Fork 4
/
esbuild.js
72 lines (63 loc) · 1.65 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
68
69
70
71
72
import * as esbuild from "esbuild";
import { litCssPlugin } from "esbuild-plugin-lit-css";
import { copy } from "esbuild-plugin-copy";
import { readFileSync } from "fs";
import CleanCSS from "clean-css";
const loadJSON = (path) => JSON.parse(readFileSync(new URL(path, import.meta.url)));
const args = process.argv.slice(2);
const dev = args.includes("--dev");
const watch = args.includes("--watch");
const { compilerOptions } = loadJSON("./tsconfig.json");
const { name, version } = loadJSON("./package.json");
const cleanCSS = new CleanCSS({
sourceMap: true,
returnPromise: true,
});
const outdir = compilerOptions.outDir;
const outfile = `${outdir}/js/${name}.js`;
const config = {
entryPoints: ["src/index.ts"],
outfile: outfile,
format: "iife",
target: [compilerOptions.target, "chrome73", "edge79", "firefox63", "safari12"],
bundle: true,
sourcemap: !!dev,
minify: !dev,
legalComments: "linked",
logLevel: "info",
plugins: [
litCssPlugin({
include: ["src/component/**/*.css"],
transform: source => cleanCSS.minify(source).then(x => x.styles)
}),
copy({
assets: [
{
from: ["src/icons/*"],
to: ["../icons"],
},
{
from: ["node_modules/pdfjs-dist/build/pdf.worker.min.js"],
to: ["pdf.worker.js"],
}
]
})
]
};
if (watch) {
const context = await esbuild.context(config);
// Enable watch mode.
await context.watch();
function handleCleanup() {
// Close the esbuild context when the process is exiting.
context?.dispose();
process.exit();
}
// Cleanup on exit.
process.on("SIGINT", handleCleanup);
process.on("SIGTERM", handleCleanup);
}
else {
// Building source files.
await esbuild.build(config);
}