-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathbuild.js
82 lines (73 loc) · 1.98 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
70
71
72
73
74
75
76
77
78
79
80
81
82
/* eslint import/no-extraneous-dependencies: 0 */
const { execSync } = require('child_process')
const rollup = require('rollup')
const babel = require('rollup-plugin-babel')
const { eslint } = require('rollup-plugin-eslint')
const resolve = require('rollup-plugin-node-resolve')
const commonjs = require('rollup-plugin-commonjs')
const { uglify } = require('rollup-plugin-uglify')
const string = require('rollup-plugin-string')
const json = require('rollup-plugin-json')
const builtins = require('rollup-plugin-node-builtins')
const defaultPlugins = [
json({
include: 'package.json'
}),
string({
include: '**/*.css'
}),
resolve({
jsnext: true,
main: true,
browser: true,
preferBuiltins: false
}),
commonjs({
include: 'node_modules/**',
namedExports: {
'node_modules/bluebird/js/browser/bluebird.js': ['promisify']
}
}),
eslint({
exclude: ['src/css/**', 'node_modules/**', 'lib/images/**']
}),
babel({
exclude: 'node_modules/**',
runtimeHelpers: true
}),
builtins()
]
function transpileEs5NodeModules() {
// specify any non-es5 modules here
const nonEs5Modules = ['ow', 'punycode']
nonEs5Modules.forEach(m =>
execSync(
`node_modules/.bin/babel node_modules/${m} --out-dir node_modules/${m} --presets=@babel/preset-env`
)
)
}
const inputOptions = min => ({
input: 'src/js/index.js',
plugins: min ? [...defaultPlugins, uglify()] : defaultPlugins
})
const outputOptions = min => ({
format: 'umd',
file: min ? 'lib/assist.min.js' : 'lib/assist.js',
name: 'assist',
globals: {
bluebird: 'promisify',
bowser: 'bowser'
},
sourceMap: 'inline'
})
async function build() {
// transpile non-es5 node_modules
transpileEs5NodeModules()
// create a regular bundle
const bundle = await rollup.rollup(inputOptions())
await bundle.write(outputOptions())
// create a minified bundle
const minBundle = await rollup.rollup(inputOptions('min'))
await minBundle.write(outputOptions('min'))
}
build()