-
Notifications
You must be signed in to change notification settings - Fork 6
/
builder.js
48 lines (42 loc) · 1020 Bytes
/
builder.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
const fs = require('fs');
const { rollup } = require('rollup');
const { minify } = require('uglify-js');
const pretty = require('pretty-bytes');
const sizer = require('gzip-size');
const pkg = require('./package');
const umd = pkg['umd:main'];
rollup({
useStrict: false,
entry: 'src/index.js',
plugins: [
require('rollup-plugin-node-resolve')(),
require('rollup-plugin-buble')({
transform: { module:false }
}),
]
}).then(bun => {
bun.write({
format: 'cjs',
dest: pkg.main,
exports: 'default'
});
bun.write({
format: 'es',
dest: pkg.module,
exports: 'default'
});
bun.write({
dest:umd,
format: 'umd',
exports: 'default',
moduleName: pkg.name
}).then(_ => {
const data = fs.readFileSync(umd, 'utf8');
// produce minified output
const { code } = minify(data, { fromString:true });
fs.writeFileSync(umd, code);
// output gzip size
const int = sizer.sync(code);
console.log(`> gzip size: ${ pretty(int) }`);
}).catch(console.log);
}).catch(err => console.log(err))