-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.mjs
54 lines (47 loc) · 1.59 KB
/
build.mjs
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
import esbuild from "esbuild";
import { copy } from "esbuild-plugin-copy";
import inlineImage from "esbuild-plugin-inline-image";
import eslint from 'esbuild-plugin-eslint';
import { zip } from 'zip-a-folder';
import { rmSync } from 'node:fs';
import { postcssModules, sassPlugin } from 'esbuild-sass-plugin'
const removeFile = (path) => {
console.log(`Removing ${path}`)
rmSync(path, { recursive: true, force: true });
}
const args = process.argv.slice(2);
const PROD = args.includes("prod");
const WATCH = args.includes("watch");
const esbuildPlugins = [inlineImage(), sassPlugin({
filter: /\.module\.s?css$/,
transform: postcssModules({})
}), sassPlugin(), copy({
// this is equal to process.cwd(), which means we use cwd path as base path to resolve `to` path
// if not specified, this plugin uses ESBuild.build outdir/outfile options as base path.
resolveFrom: 'cwd',
assets: {
from: ['./public/*'],
to: ['./build'],
},
})];
if (PROD) esbuildPlugins.push(eslint({ throwOnWarning: true })); //lint production build
const esbuildConfig = {
entryPoints: ["./src/index.tsx", "./src/chromeServices/background/index.ts", "./src/chromeServices/contentScript/index.ts"],
outdir: "./build",
minify: PROD,
bundle: true,
plugins: esbuildPlugins,
logLevel: "info",
sourcemap: !PROD,
};
removeFile("./build");
if (!WATCH) {
await esbuild.build(esbuildConfig);
if (PROD) {
removeFile("./build.zip");
await zip("./build", "./build.zip");
}
} else {
const ctx = await esbuild.context(esbuildConfig);
await ctx.watch();
}