forked from robinweser/inline-style-prefixer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuildPackage.js
62 lines (52 loc) · 1.72 KB
/
buildPackage.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
/* eslint-disable no-console */
import rollup from 'rollup'
import babel from 'rollup-plugin-babel'
import uglify from 'rollup-plugin-uglify'
import commonjs from 'rollup-plugin-commonjs'
import nodeResolver from 'rollup-plugin-node-resolve'
const packages = {
'inline-style-prefixer': {
name: 'InlineStylePrefixer',
entry: 'Prefixer.js'
},
'inline-style-prefix-all': {
name: 'InlineStylePrefixAll',
entry: '/static/prefixAll.js'
}
}
// Small helper to error and exit on fail
const errorOnFail = err => {
if (err) {
console.error(err)
process.exit(1)
}
}
const babelPlugin = babel({
babelrc: false,
presets: [ 'es2015-rollup', 'stage-0' ]
})
const nodeResolverPlugin = nodeResolver({ jsnext: true, main: true })
const commonJSPlugin = commonjs({ include: 'node_modules/**' })
const uglifyPlugin = uglify()
const plugins = [ babelPlugin, nodeResolverPlugin, commonJSPlugin ]
function rollupConfig(pkg, info, minify) {
return {
entry: 'modules/' + info.entry,
plugins: minify ? plugins.concat(uglifyPlugin) : plugins
}
}
function bundleConfig(pkg, info, minify) {
return {
format: 'umd',
moduleName: info.name,
dest: 'dist/' + pkg + (minify ? '.min' : '') + '.js',
sourceMap: !minify
}
}
function buildPackage(pkg) {
rollup.rollup(rollupConfig(pkg, packages[pkg], process.env.NODE_ENV === 'production')).then(bundle => {
bundle.write(bundleConfig(pkg, packages[pkg], process.env.NODE_ENV === 'production'))
console.log('Successfully bundled ' + packages[pkg].name + (process.env.NODE_ENV === 'production' ? ' (minified).' : '.'))
}).catch(errorOnFail)
}
Object.keys(packages).forEach(pkg => buildPackage(pkg))