forked from jquery/jquery-mousewheel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathminify.mjs
37 lines (31 loc) · 878 Bytes
/
minify.mjs
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
import fs from "node:fs/promises";
import path from "node:path";
import swc from "@swc/core";
const rjs = /\.js$/;
export async function minify( { filename, dir } ) {
const contents = await fs.readFile( path.join( dir, filename ), "utf8" );
const { code } = await swc.minify(
contents,
{
compress: {
ecma: 5,
hoist_funs: false,
loops: false
},
format: {
ecma: 5,
asciiOnly: true
},
inlineSourcesContent: false,
mangle: true,
module: false,
sourceMap: false
}
);
const minFilename = filename.replace( rjs, ".min.js" );
await fs.writeFile(
path.join( dir, minFilename ),
code
);
console.log( `file ${ minFilename } created.` );
}