-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathminify.js
41 lines (40 loc) · 979 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
40
41
const fs = require('fs');
const path = require('path')
const terser = require('terser')
// Minify code
let min = terser.minify(fs.readFileSync(path.join(__dirname,'/web.js'),'utf8'), {
sourceMap: {
filename:`web.js.map`,
url: `web.js.map`
},
compress: {
"arrows": false,
"keep_infinity": true,
"passes": 1,
},
format: {
"comments": false,
"ie8": true,
"safari10": true,
"webkit": true,
"quote_style": 0
},
mangle: { }
});
min.then(function (output) {
fs.writeFileSync(
path.join(__dirname,'/web.min.js'),
output.code
)
output.map = JSON.parse(output.map)
output.map.sources[0] = `web.js`;
output.map = JSON.stringify(output.map)
fs.writeFileSync(
path.join(__dirname,'/web.js.map'),
output.map
)
})
.catch(function (err) {
console.log(err);
throw new Error("Faced problems while minifying code")
})