-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathminify.js
39 lines (33 loc) · 912 Bytes
/
minify.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
const terser = require("terser");
const fs = require("fs").promises;
const path = require("path");
const inputFiles = [
"src/script.js",
"src/board.js",
"src/dfs.js",
"src/theme.js",
];
const outputFilePath = "dist/script.js";
const minifyOptions = {
compress: true,
mangle: false,
sourceMap: true,
};
async function minifyFiles() {
try {
const modules = await Promise.all(
inputFiles.map((file) => fs.readFile(file, "utf8"))
);
const concatenatedCode = modules.join("\n");
const result = await terser.minify(concatenatedCode, minifyOptions);
if (result.error) {
console.error("Error during minification:", result.error);
} else {
await fs.mkdir(path.dirname(outputFilePath), { recursive: true });
await fs.writeFile(outputFilePath, result.code);
}
} catch (error) {
console.error("An error occurred:", error);
}
}
minifyFiles();