-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
build-rollup.js
71 lines (62 loc) · 1.68 KB
/
build-rollup.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
70
71
const path = require('path')
const filesize = require('rollup-plugin-filesize')
const babel = require('rollup-plugin-babel')
const commonjs = require('rollup-plugin-commonjs')
const resolve = require('rollup-plugin-node-resolve')
const { uglify } = require('rollup-plugin-uglify')
const { rollup } = require('rollup')
function build(format, filename, { min = false } = {}) {
const plugins = [
babel({
exclude: 'node_modules/**',
"presets": [
[ "es2015-rollup" ],
"stage-1"
],
"plugins": [
[ "transform-react-jsx", { "pragma": "h" }],
"transform-decorators-legacy"
],
babelrc: false,
}),
resolve({
module: true,
main: true,
}),
commonjs(),
]
if (min) {
plugins.push(
uglify({
ie8: false,
warnings: false
})
)
}
plugins.push(filesize())
return rollup({
input: 'src/index.js',
external: ['preact', 'mobx'],
plugins: plugins
}).then(bundle => {
const options = {
file: path.resolve(process.cwd(), 'lib', filename),
format,
name: 'mobxPreact',
exports: 'named',
globals: {
preact: 'preact',
mobx: 'mobx'
},
}
return bundle.write(options);
}).catch(err => {
console.error(err);
process.exit(1);
});
}
Promise.all([
build('umd', 'index.js'),
build('umd', 'index.min.js', { min :true }),
build('es', 'index.module.js'),
]);