-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathminify.js
More file actions
34 lines (27 loc) · 829 Bytes
/
minify.js
File metadata and controls
34 lines (27 loc) · 829 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 { minify } = require('@swc/core');
const fs = require('fs');
const path = require('path');
const inputFile = 'yo.js';
const outputPaths = ['yo.min.js', 'dist/yo.min.js'];
(async () => {
const code = fs.readFileSync(inputFile, 'utf8');
for (const outPath of outputPaths) {
try {
const result = await minify(code, {
compress: true,
mangle: true,
// sourceMap: true,
});
fs.mkdirSync(path.dirname(outPath), { recursive: true });
fs.writeFileSync(outPath, result.code);
if (result.map) {
fs.writeFileSync(outPath + '.map', result.map);
}
console.log(`Created → ${outPath}`);
} catch (err) {
console.error(`Failed: ${outPath}`, err);
process.exit(1);
}
}
console.log('Done! All minified versions created.');
})();