-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
/
build.js
69 lines (61 loc) · 1.4 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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'];
const date = new Date();
const banner = `/*
* anime.js v${ pkg.version }
* (c) ${ date.getFullYear() } Julian Garnier
* Released under the MIT license
* animejs.com
*/
`;
console.info('Compiling... 😤');
rollup({
input: 'src/index.js',
plugins: [
require('rollup-plugin-buble')({
transforms: {
modules: false,
dangerousForOf: true
},
targets: {
firefox: 32,
chrome: 24,
safari: 6,
opera: 15,
edge: 10,
ie: 10
}
})
]
}).then(bun => {
bun.write({
banner,
format: 'cjs',
file: pkg.main
});
bun.write({
banner,
format: 'es',
file: pkg.module
});
bun.write({
banner,
file: umd,
format: 'umd',
name: pkg['umd:name']
}).then(_ => {
const data = fs.readFileSync(umd, 'utf8');
// produce minified output
const { code } = minify(data);
fs.writeFileSync(umd, `${banner}\n${code}`); // with banner
// output gzip size
const int = sizer.sync(code);
console.info('Compilation was a success! 👍');
console.info(`~> gzip size: ${ pretty(int) }`);
}).catch(console.error);
}).catch(console.error);