|
1 |
| -import * as childx from "child_process"; |
2 |
| -import fs from "fs"; |
| 1 | +import * as childx from "child_process"; // Node.js child_process module |
| 2 | +import fs from "fs"; // Node.js file system module |
3 | 3 |
|
4 | 4 | import resolve from "rollup-plugin-node-resolve";
|
5 | 5 | import commonjs from "rollup-plugin-commonjs";
|
6 |
| -import { terser } from "rollup-plugin-terser"; |
| 6 | +import { |
| 7 | + terser |
| 8 | +} from "rollup-plugin-terser"; |
7 | 9 | import builtins from "builtin-modules";
|
8 | 10 | import globals from "rollup-plugin-node-globals";
|
9 | 11 | import builtins2 from "rollup-plugin-node-builtins";
|
10 | 12 | import json from "rollup-plugin-json";
|
11 | 13 | import replace from "rollup-plugin-replace";
|
12 | 14 |
|
13 |
| -var minify = false; |
14 |
| -var productionEnv = false; |
| 15 | +let minify = false; |
| 16 | +let productionEnv = false; |
15 | 17 |
|
16 | 18 | run("./src/renderer", "./renderer", minify);
|
17 | 19 | run("./src/main", "./main", minify);
|
18 | 20 |
|
19 |
| -var exp = [ |
20 |
| - // main process (nodejs) |
21 |
| - { |
22 |
| - input: "./main_go.js", |
23 |
| - output: { |
24 |
| - file: "./main.js", |
25 |
| - format: "cjs", |
26 |
| - sourcemap: false |
27 |
| - }, |
28 |
| - external: ["electron", ...builtins], |
29 |
| - plugins: [ |
30 |
| - resolve(), |
31 |
| - commonjs({}), |
32 |
| - globals(), |
33 |
| - builtins2(), |
34 |
| - minify |
35 |
| - ? terser({ ecma: 6 }) |
36 |
| - : { name: "x", generateBundle: function() {} }, |
37 |
| - deleteFile("./main_go.js"), |
38 |
| - deleteFile("./main_go.js.map") |
39 |
| - ] |
40 |
| - }, |
41 |
| - // renderer process (browser) |
42 |
| - { |
43 |
| - input: "./renderer_go.js", |
44 |
| - output: { |
45 |
| - file: "./renderer.js", |
46 |
| - format: "iife", |
47 |
| - sourcemap: false, |
48 |
| - name: "main" |
49 |
| - }, |
50 |
| - external: ["electron"], |
51 |
| - plugins: [ |
52 |
| - resolve({ |
53 |
| - browser: true, |
54 |
| - preferBuiltins: true, |
55 |
| - dedupe: ["react", "react-dom"] |
56 |
| - }), |
57 |
| - replace({ |
58 |
| - "process.env.NODE_ENV": JSON.stringify( |
59 |
| - productionEnv ? "production" : "development" |
60 |
| - ) |
61 |
| - }), |
62 |
| - json(), |
63 |
| - commonjs({}), |
64 |
| - globals(), |
65 |
| - builtins2(), |
66 |
| - minify |
67 |
| - ? terser({ ecma: 6 }) |
68 |
| - : { name: "x", generateBundle: function() {} }, |
69 |
| - deleteFile("./renderer_go.js"), |
70 |
| - deleteFile("./renderer_go.js.map") |
71 |
| - ] |
72 |
| - } |
| 21 | +export default [ |
| 22 | + // main process (nodejs) config |
| 23 | + { |
| 24 | + input: "./main_go.js", |
| 25 | + output: { |
| 26 | + file: "./main.js", |
| 27 | + format: "cjs", |
| 28 | + sourcemap: false |
| 29 | + }, |
| 30 | + external: ["electron", ...builtins], |
| 31 | + plugins: [ |
| 32 | + resolve(), |
| 33 | + commonjs({}), |
| 34 | + globals(), |
| 35 | + builtins2(), |
| 36 | + minify ? |
| 37 | + terser({ |
| 38 | + ecma: 6 |
| 39 | + }) : |
| 40 | + { |
| 41 | + name: "x", |
| 42 | + generateBundle: function () {} |
| 43 | + }, |
| 44 | + deleteFile("./main_go.js"), |
| 45 | + deleteFile("./main_go.js.map") |
| 46 | + ] |
| 47 | + }, |
| 48 | + // renderer process (browser) config |
| 49 | + { |
| 50 | + input: "./renderer_go.js", |
| 51 | + output: { |
| 52 | + file: "./renderer.js", |
| 53 | + format: "iife", |
| 54 | + sourcemap: false, |
| 55 | + name: "main" |
| 56 | + }, |
| 57 | + external: ["electron"], |
| 58 | + plugins: [ |
| 59 | + resolve({ |
| 60 | + browser: true, |
| 61 | + preferBuiltins: true, |
| 62 | + dedupe: ["react", "react-dom"] |
| 63 | + }), |
| 64 | + replace({ |
| 65 | + "process.env.NODE_ENV": JSON.stringify( |
| 66 | + productionEnv ? "production" : "development" |
| 67 | + ) |
| 68 | + }), |
| 69 | + json(), |
| 70 | + commonjs({}), |
| 71 | + globals(), |
| 72 | + builtins2(), |
| 73 | + minify ? |
| 74 | + terser({ |
| 75 | + ecma: 6 |
| 76 | + }) : |
| 77 | + { |
| 78 | + name: "x", |
| 79 | + generateBundle: function () {} |
| 80 | + }, |
| 81 | + deleteFile("./renderer_go.js"), |
| 82 | + deleteFile("./renderer_go.js.map") |
| 83 | + ] |
| 84 | + } |
73 | 85 | ];
|
74 | 86 |
|
75 |
| -export default exp; |
76 |
| - |
77 | 87 | function run(input, output, minify) {
|
78 |
| - var path = "gopherjs build " + input; |
79 |
| - if (minify) { |
80 |
| - path = path + " -m "; |
81 |
| - } |
| 88 | + let path = "gopherjs build " + input; |
| 89 | + if (minify) { |
| 90 | + path = path + " -m "; |
| 91 | + } |
82 | 92 |
|
83 |
| - output = output + "_go"; |
| 93 | + output = output + "_go"; |
84 | 94 |
|
85 |
| - path = path + " -o " + output + ".js"; |
| 95 | + path = path + " -o " + output + ".js"; |
86 | 96 |
|
87 |
| - childx.execSync(path); |
| 97 | + childx.execSync(path); |
88 | 98 | }
|
89 | 99 |
|
90 | 100 | function deleteFile(filePath) {
|
91 |
| - return { |
92 |
| - name: "deleteFile", |
93 |
| - writeBundle: function() { |
94 |
| - fs.unlinkSync(filePath); |
95 |
| - } |
96 |
| - }; |
| 101 | + return { |
| 102 | + name: "deleteFile", |
| 103 | + writeBundle: function () { |
| 104 | + fs.unlinkSync(filePath); |
| 105 | + } |
| 106 | + }; |
97 | 107 | }
|
| 108 | + |
0 commit comments