-
Notifications
You must be signed in to change notification settings - Fork 4
/
build.js
40 lines (32 loc) · 1.01 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
const fs = require("fs");
const { minify } = require("uglify-js");
const ElmCompiler = require("node-elm-compiler");
fs.mkdirSync("lib", { recursive: true });
const elmDts = fs.readFileSync("src/elm.d.ts", { encoding: "utf-8" });
const fixedElmDts = elmDts
.split("\n")
.filter((line) => !(line.startsWith("declare") || line.startsWith("}")))
.map((line) => line.slice(2, line.length))
.join("\n");
fs.writeFileSync("lib/elm.min.d.ts", fixedElmDts);
const isRelease = process.env.NODE_ENV === "production";
let elmCode = ElmCompiler.compileToStringSync("src/Main.elm", {
optimize: isRelease,
});
if (isRelease) {
const minifiedResult = minify(elmCode, {
compress: {
pure_funcs: "F2,F3,F4,F5,F6,F7,F8,F9,A2,A3,A4,A5,A6,A7,A8,A9",
pure_getters: true,
keep_fargs: false,
unsafe_comps: true,
unsafe: true,
},
mangle: true,
});
if (minifiedResult.error) {
throw minifiedResult.error;
}
elmCode = minifiedResult.code;
}
fs.writeFileSync("lib/elm.min.js", elmCode);