-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
51 lines (45 loc) · 1.64 KB
/
build.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
42
43
44
45
46
47
48
49
50
51
const { writeFileSync, statSync } = require('fs');
const { execSync } = require('child_process');
const amp = require('./amp.json');
const showFileSize = (file1, file2) => {
const { size: size1 } = statSync(file1);
const { size: size2 } = statSync(file2);
console.log(
[
`${file1} ${size1}(Bytes)`,
`${file2} ${size2}(Bytes)`,
`${100 - Math.round((size2 / size1) * 100)}%`
].join(' | ')
);
};
const commands = [
`rm -rf ${__dirname}/dist`,
`mkdir -p ${__dirname}/dist`,
`cd ${__dirname}/dist`,
// a.js
`cp ${__dirname}/a.js ${__dirname}/dist/a.src.js`,
`${__dirname}/node_modules/.bin/uglifyjs a.src.js -cmo a.js`,
// l.js
`cp ${__dirname}/l.js ${__dirname}/dist/l.src.js`,
`${__dirname}/node_modules/.bin/uglifyjs l.src.js -cmo l.js`,
// script.js
`cp ${__dirname}/script.js ${__dirname}/dist/script.src.js`,
`${__dirname}/node_modules/.bin/uglifyjs script.src.js -cmo script.js`,
`rm script.src.js`,
// script-debug.js
`cp ${__dirname}/script-debug.js ${__dirname}/dist/script-debug.js`,
// script.modern.js
`cp ${__dirname}/script.modern.js ${__dirname}/dist/script.modern.src.js`,
`${__dirname}/node_modules/.bin/uglifyjs script.modern.src.js -cmo script.modern.js`,
`rm script.modern.src.js`
];
execSync(commands.join(' && '));
writeFileSync(`${__dirname}/dist/amp.json`, JSON.stringify(amp).trim(), {
encoding: 'utf8'
});
showFileSize(`a.js`, `dist/a.js`);
showFileSize(`l.js`, `dist/l.js`);
showFileSize(`script.js`, `dist/script.js`);
showFileSize(`script-debug.js`, `dist/script-debug.js`);
showFileSize(`script.modern.js`, `dist/script.modern.js`);
showFileSize(`amp.json`, `dist/amp.json`);