-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathminify.js
More file actions
executable file
·34 lines (30 loc) · 1021 Bytes
/
Copy pathminify.js
File metadata and controls
executable file
·34 lines (30 loc) · 1021 Bytes
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
const fs = require("fs");
const path = require("path");
const { execSync } = require("child_process");
const directory = "dist";
function minifyDirectory(dir) {
fs.readdir(dir, { withFileTypes: true }, (err, entries) => {
if (err) {
console.error("Error reading directory:", err);
return;
}
entries.forEach((entry) => {
const entryPath = path.join(dir, entry.name);
if (entry.isDirectory()) {
console.log(`Entering directory: ${entryPath}`);
minifyDirectory(entryPath); // Recursively minify files in subdirectory
} else if (path.extname(entry.name) === ".js") {
console.log(`Processing file: ${entryPath}`);
try {
execSync(
`terser ${entryPath} --output ${entryPath} --compress --mangle`
);
console.log(`${entry.name} minified successfully.`);
} catch (error) {
console.error(`Error minifying ${entry.name}:`, error);
}
}
});
});
}
minifyDirectory(directory);