-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrollup.config.js
108 lines (98 loc) · 2.24 KB
/
rollup.config.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import * as childx from "child_process"; // Node.js child_process module
import fs from "fs"; // Node.js file system module
import resolve from "rollup-plugin-node-resolve";
import commonjs from "rollup-plugin-commonjs";
import {
terser
} from "rollup-plugin-terser";
import builtins from "builtin-modules";
import globals from "rollup-plugin-node-globals";
import builtins2 from "rollup-plugin-node-builtins";
import json from "rollup-plugin-json";
import replace from "rollup-plugin-replace";
let minify = false;
let productionEnv = false;
run("./src/renderer", "./renderer", minify);
run("./src/main", "./main", minify);
export default [
// main process (nodejs) config
{
input: "./main_go.js",
output: {
file: "./main.js",
format: "cjs",
sourcemap: false
},
external: ["electron", ...builtins],
plugins: [
resolve(),
commonjs({}),
globals(),
builtins2(),
minify ?
terser({
ecma: 6
}) :
{
name: "x",
generateBundle: function () {}
},
deleteFile("./main_go.js"),
deleteFile("./main_go.js.map")
]
},
// renderer process (browser) config
{
input: "./renderer_go.js",
output: {
file: "./renderer.js",
format: "iife",
sourcemap: false,
name: "main"
},
external: ["electron"],
plugins: [
resolve({
browser: true,
preferBuiltins: true,
dedupe: ["react", "react-dom"]
}),
replace({
"process.env.NODE_ENV": JSON.stringify(
productionEnv ? "production" : "development"
)
}),
json(),
commonjs({}),
globals(),
builtins2(),
minify ?
terser({
ecma: 6
}) :
{
name: "x",
generateBundle: function () {}
},
deleteFile("./renderer_go.js"),
deleteFile("./renderer_go.js.map")
]
}
];
function run(input, output, minify) {
let path = "gopherjs build " + input;
if (minify) {
path = path + " -m ";
}
output = output + "_go";
path = path + " -o " + output + ".js";
childx.execSync(path);
}
function deleteFile(filePath) {
return {
name: "deleteFile",
writeBundle: function () {
fs.unlinkSync(filePath);
}
};
}