-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
83 lines (72 loc) · 1.54 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import esbuild from "esbuild";
const scriptName = "alpine-mousedrag-plugin";
const watching = process.argv.includes("--watch");
function build(options = {}) {
options.define || (options.define = {});
options.define["process.env.NODE_ENV"] = watching
? `'development'`
: `'production'`;
return esbuild
.build({
...options,
})
.catch((e) => {
process.exit(1);
});
}
function buildScripts() {
// CDN
build({
entryPoints: ["src/index.ts"],
outfile: `dist/${scriptName}.js`,
bundle: true,
platform: "browser",
});
if (!watching) {
build({
entryPoints: ["src/index.ts"],
outfile: `dist/example.js`,
bundle: true,
platform: "browser",
});
}
// CDN — minified
build({
entryPoints: ["src/index.ts"],
outfile: `dist/${scriptName}.min.js`,
bundle: true,
minify: true,
platform: "browser",
});
// ESM
build({
entryPoints: ["src/index.ts"],
outfile: `dist/${scriptName}.esm.js`,
bundle: true,
platform: "neutral",
mainFields: ["module", "main"],
});
// CommonJS
build({
entryPoints: ["src/index.ts"],
outfile: `dist/${scriptName}.cjs.js`,
bundle: true,
target: ["node10.4"],
platform: "node",
});
}
async function watch() {
let ctx = await esbuild.context({
entryPoints: ["src/index.ts"],
bundle: true,
outfile: "dist/example.js",
});
await ctx.watch();
}
if (watching) {
console.log("🎵 Aaaaaaaa WATCH ME NOW 🎵");
watch();
buildScripts();
} else {
buildScripts();
}