forked from hgiesel/anki_new_format_pack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.mjs
64 lines (57 loc) · 1.51 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
55
56
57
58
59
60
61
62
63
64
import * as fs from "fs";
import { env } from "process";
import * as esbuild from "esbuild";
import sveltePlugin from "esbuild-svelte";
import sveltePreprocess from "svelte-preprocess";
import { sassPlugin } from "esbuild-sass-plugin";
for (const dir of ["../dist", "../dist/web"]) {
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir);
}
}
const production = env.NODE_ENV === "production";
const development = env.NODE_ENV === "development";
/**
* This should point to all entry points for JS add-ons.
* Each one will create one js and one css file in `../src/dist/web'
*/
const entryPoints = ["src/editor.ts"];
/**
* Esbuild build options
* See https://esbuild.github.io/api/#build-api for more
*/
const options = {
entryPoints,
outdir: "../dist/web",
format: "iife",
target: "es6",
bundle: true,
minify: production,
treeShaking: production,
sourcemap: !production,
pure: production ? ["console.log", "console.time", "console.timeEnd"] : [],
external: ["svelte", "anki"],
plugins: [
sveltePlugin({
preprocess: sveltePreprocess({
scss: {
includePaths: ["anki/sass"],
},
}),
}),
sassPlugin(),
],
loader: {
".png": "dataurl",
".svg": "text",
},
};
const context = await esbuild.context(options);
if (development) {
console.log("Watching for changes...");
await context.watch();
}
else {
await context.rebuild();
context.dispose();
}