-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
rollup.config.js
128 lines (124 loc) · 2.21 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import fs from "fs";
import replace from "replace-in-file";
import { terser } from "rollup-plugin-terser";
export default [
{
input: "src/renderer.js",
output: {
file: "dist/renderer.js",
format: "esm",
sourcemap: false
},
external: ["electron"],
plugins: [
terser({
ecma: 6,
mangle: {
reserved: ["uid", "sound", "config"]
}
})
]
},
{
input: "src/alert.js",
output: {
file: "dist/alert.js",
format: "cjs",
sourcemap: false
},
external: [
"electron",
"crypto-random-string",
"electron-positioner",
"temp-write",
"exception-formatter"
],
plugins: [
stringReplace(
"./dist/alert.js",
/<@insert-renderer@>/,
"./dist/renderer.js"
),
stringReplace(
"./dist/alert.js",
/<@insert-swal-lib@>/,
"node_modules/sweetalert2/dist/sweetalert2.all.min.js"
),
deleteFile("./dist/renderer.js")
]
},
// Minified version
{
input: "src/renderer.js",
output: {
file: "dist/renderer.min.js",
format: "esm",
sourcemap: false
},
external: ["electron"],
plugins: [
terser({
ecma: 6,
mangle: {
reserved: ["uid", "sound", "config"]
}
})
]
},
{
input: "src/alert.js",
output: {
file: "dist/alert.min.js",
format: "cjs",
sourcemap: false
},
external: [
"electron",
"crypto-random-string",
"electron-positioner",
"temp-write",
"exception-formatter"
],
plugins: [
terser({
ecma: 6,
mangle: {
reserved: ["uid", "sound", "config"]
}
}),
stringReplace(
"./dist/alert.min.js",
/<@insert-renderer@>/,
"./dist/renderer.min.js"
),
stringReplace(
"./dist/alert.min.js",
/<@insert-swal-lib@>/,
"node_modules/sweetalert2/dist/sweetalert2.all.min.js"
),
deleteFile("./dist/renderer.min.js")
]
}
];
function stringReplace(file, tag, toFile) {
return {
name: "stringReplace",
writeBundle: function() {
var js = fs.readFileSync(toFile, "utf8");
js = js.replace(/`/g, String.fromCharCode(92, 96)); // ` => \`
replace.sync({
files: file,
from: tag,
to: js
});
}
};
}
function deleteFile(filePath) {
return {
name: "deleteFile",
writeBundle: function() {
fs.unlinkSync(filePath);
}
};
}