forked from Tencent/wepy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.js
More file actions
60 lines (49 loc) · 1.28 KB
/
build.js
File metadata and controls
60 lines (49 loc) · 1.28 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
50
51
52
53
54
55
56
57
58
59
60
const path = require('path');
const fs = require('fs-extra');
const rollup = require('rollup');
const buble = require('rollup-plugin-buble');
const replace = require('rollup-plugin-replace');
const config = require('./config');
function build (config) {
let output = config.output;
let { file, banner } = output;
return rollup.rollup(config).then(bundle => bundle.generate(output))
.then(rst => {
write(file, rst.code);
})
.catch(e => {
console.log(e);
})
}
function write (dest, code, zip) {
return new Promise((resolve, reject) => {
function report (extra) {
console.log(blue(path.relative(process.cwd(), dest)) + ' ' + getSize(code) + (extra || ''))
resolve()
}
fs.outputFile(dest, code).then(() => {
if (zip) {
zlib.gzip(code, (err, zipped) => {
if (err)
return reject(err);
report(' (gzipped: ' + getSize(zipped) + ')')
})
} else {
report();
}
}).catch(reject);
})
}
function getSize (code) {
return (code.length / 1024).toFixed(2) + 'kb'
}
function logError (e) {
console.log(e)
}
function blue (str) {
return '\x1b[1m\x1b[34m' + str + '\x1b[39m\x1b[22m'
}
let configs = config.getAllBuilds();
configs.forEach(config => {
build(config);
});