-
Notifications
You must be signed in to change notification settings - Fork 1
/
bundle.js
75 lines (72 loc) · 2.53 KB
/
bundle.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
72
73
74
75
const babel = require('rollup-plugin-babel')
const commonJs = require('rollup-plugin-commonjs')
const fs = require('fs')
const Promise = require('bluebird')
const replace = require('rollup-plugin-replace')
const resolve = require('rollup-plugin-node-resolve')
const rollup = require('rollup').rollup
const uglify = require('rollup-plugin-uglify')
Promise.promisifyAll(fs)
const build = ({ dest, entry, format, plugins }) => new Promise((resolve, reject) => {
rollup({ entry, plugins })
.then(bundle => bundle.write({ dest, format, moduleName: 'WildernessDomNode' })
.then(resolve))
.catch(reject)
})
Promise.resolve(console.log('Creating UMD development bundle ...'))
.then(() => build({
dest: 'dist/wilderness-dom-node.development.js',
entry: 'src/index.js',
format: 'umd',
plugins: [
babel({
exclude: 'node_modules/**',
plugins: [ 'transform-object-rest-spread', 'external-helpers' ],
presets: [[ 'es2015', { 'modules': false } ]]
}),
commonJs(),
resolve({ module: true }),
replace({ '__DEV__': true })
]
}))
.then(() => Promise.resolve(console.log('UMD development bundle complete')))
.then(() => Promise.resolve(console.log('Creating UMD production bundle ...')))
.then(() => build({
dest: 'dist/wilderness-dom-node.production.js',
entry: 'src/index.js',
format: 'umd',
plugins: [
babel({
exclude: 'node_modules/**',
plugins: [ 'transform-object-rest-spread' ],
presets: [[ 'es2015', { 'modules': false } ]]
}),
commonJs(),
resolve({ module: true }),
replace({ '__DEV__': false }),
uglify()
]
}))
.then(() => Promise.resolve(console.log('UMD production bundle complete')))
.then(() => Promise.resolve(console.log('Creating example bundles ...')))
.then(() => fs.readdirAsync('examples')
.then(files => Promise.filter(files, f => fs.lstatAsync(`examples/${f}`).then(x => Promise.resolve(x.isDirectory()))))
.then(directories => Promise.all(directories.map(dir => (
build({
dest: `examples/${dir}/dist.js`,
entry: `examples/${dir}/src.js`,
format: 'iife',
plugins: [
babel({
exclude: 'node_modules/**',
plugins: [ 'transform-object-rest-spread' ],
presets: [[ 'es2015', { 'modules': false } ]]
}),
commonJs(),
resolve({ module: true }),
replace({ '__DEV__': true })
]
})
))))
.then(() => Promise.resolve(console.log('Example bundles complete')))
.catch(e => console.error(e)))