forked from ApoorvSaxena/lozad.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
74 lines (67 loc) · 1.62 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
const {rollup} = require('rollup')
const babel = require('rollup-plugin-babel')
const filesize = require('rollup-plugin-filesize')
const uglify = require('rollup-plugin-uglify')
const license = require('rollup-plugin-license')
const chokidar = require('chokidar')
const targets = {
umd: 'dist/lozad.js',
min: 'dist/lozad.min.js'
}
function build(format) {
const defaultPlugins = [
license({
banner:
'/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - ' +
'<%= moment().format("YYYY-MM-DD") + "\\n" %>' +
'<%= pkg.homepage ? "* " + pkg.homepage + "\\n" : "" %>' +
'* Copyright (c) <%= moment().format("YYYY") %> <%= pkg.author.name %>;' +
' Licensed <%= _.map(pkg.licenses, "type").join(", ") %> */\n\n'
}),
babel({
babelrc: false,
presets: [
[
'env',
{
modules: false
}
],
'stage-0'
]
}),
filesize()
]
const plugins =
format === 'min' ?
defaultPlugins.concat(
uglify({
output: {
comments: true
}
})
) :
defaultPlugins
return rollup({
input: 'src/lozad.js',
plugins
}).then(bundle =>
bundle.write({
file: targets[format],
format: format === 'min' ? 'umd' : format,
name: 'lozad'
})
)
}
function main() {
return Promise.all([build('umd'), build('min')]).catch(err => {
console.error(err)
})
}
main()
if (process.env.NODE_ENV === 'development') {
chokidar.watch('src/**/*.js').on('change', path => {
console.log('CHANGE: ' + path)
main()
})
}