-
Notifications
You must be signed in to change notification settings - Fork 0
/
minify.js
29 lines (24 loc) · 865 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
const Terser = require("terser");
const { globSync } = require("glob");
const fs = require("fs");
const path = require("path");
// Use a glob pattern to select all .js files in the 'src' directory and its subdirectories
console.log("minfiuing", __dirname + "/dist/**/*.js");
const files = globSync(__dirname + "/dist/esm/**/*.js", (err, files) => {});
console.log("f");
console.log(files);
files.forEach((file) => {
console.log(file);
fs.readFile(file, "utf8", async (err, data) => {
if (err) throw err;
// Minify the file contents
const result = await Terser.minify(data);
if (result.error) throw result.error;
// Write the minified contents to a new file in the 'dist' directory
const distFilePath = file;
console.log(result);
fs.writeFile(distFilePath, result.code, (err) => {
if (err) throw err;
});
});
});