forked from wilzbach/react-msa-viewer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathterser.js
More file actions
executable file
·49 lines (43 loc) · 1.35 KB
/
terser.js
File metadata and controls
executable file
·49 lines (43 loc) · 1.35 KB
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
42
43
44
45
46
47
48
49
#!/usr/bin/env node
/**
* Minifies a file with existing sourcemap with terser.
*
* arg1 {string} file to minify
* arg2 {string} output file
*/
const fs = require("fs");
const path = require("path");
const assert = require("assert");
const terser = require("terser");
const moment = require("moment");
const commenting = require("commenting");
const version = require("./package.json").version;
assert(process.argv.length >= 4, "./terser <input> <output> <preamble>");
const inFilename = process.argv[2];
const outFilename = process.argv[3];
const preamble = `react-msa-viewer ${version}
Copyright ${moment().format("YYYY")}, Plotly, Inc.
All rights reserved.
Licensed under the MIT license.
Generated: ${moment().format("YYYY-MM-DD")}
Version: ${version}
Source: https://github.com/plotly/react-msa-viewer`;
const options = {
compress: {
passes: 2,
},
mangle: true,
sourceMap: {
content: fs.readFileSync(inFilename + ".map", "utf8"),
url: path.basename(outFilename) + ".map",
},
output: {
beautify: false,
preamble: commenting(preamble.trim(), { extension: ".js" }),
},
};
console.log(`./terser ${inFilename} -> ${outFilename}`);
const code = fs.readFileSync(inFilename, "utf8");
const result = terser.minify(code, options);
fs.writeFileSync(outFilename, result.code, "utf8");
fs.writeFileSync(outFilename + ".map", result.map, "utf8");