-
Notifications
You must be signed in to change notification settings - Fork 4
/
build.js
52 lines (46 loc) · 1.28 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
52
var fs = require('fs');
var rollup = require('rollup');
var buble = require('rollup-plugin-buble');
//https://github.com/rollup/rollup-plugin-node-resolve
var resolve = require('rollup-plugin-node-resolve');
//var commonjs = require('rollup-plugin-commonjs'); // needed as dummyjs is commonjs, not a module
rollup.rollup({
input: 'src/index.js',
plugins: [buble(), resolve()]
})
.then(bundle =>
bundle.generate({
format: 'iife',
name: 'VueDummy'
}).then(({code}) => write('dist/vue-dummy.js', code, bundle))
);
rollup.rollup({
input: 'src/index.js',
plugins: [buble()]
})
//https://github.com/rollup/rollup/wiki/pkg.module
.then(bundle =>
bundle.generate({
format: 'es'
}).then(({code}) => write('dist/vue-dummy.es2015.js', code, bundle))
)
.then(bundle =>
bundle.generate({
format: 'cjs'
}).then(({code}) => write('dist/vue-dummy.cjs.js', code, bundle))
);
function write(dest, code, bundle) {
return new Promise(function (resolve, reject) {
fs.writeFile(dest, code, function (err) {
if (err) return reject(err);
console.log(blue(dest) + ' ' + getSize(code));
resolve(bundle);
});
});
}
function getSize(code) {
return (code.length / 1024).toFixed(2) + 'kb';
}
function blue(str) {
return '\x1b[1m\x1b[34m' + str + '\x1b[39m\x1b[22m';
}