-
Notifications
You must be signed in to change notification settings - Fork 870
/
build.js
73 lines (67 loc) · 1.85 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
const path = require('path')
const rollup = require('rollup')
const babel = require('rollup-plugin-babel')
const replace = require('@rollup/plugin-replace')
const { terser } = require('rollup-plugin-terser')
const resolve = require('rollup-plugin-node-resolve')
const commonjs = require('rollup-plugin-commonjs')
const version = process.env.VERSION || require('./package.json').version
const banner =
'/*!\n' +
' * Vue-Lazyload.js v' + version + '\n' +
' * (c) ' + new Date().getFullYear() + ' Awe <[email protected]>\n' +
' * Released under the MIT License.\n' +
' */\n'
async function build (options, _outputOptions) {
try {
const bundle = await rollup.rollup(options)
const outputOptions = {
format: _outputOptions.format,
exports: 'named',
banner: banner,
file: path.resolve(__dirname, _outputOptions.filename),
name: 'VueLazyload'
}
const { output } = await bundle.generate(outputOptions)
await bundle.write(outputOptions)
const code = output[0].code
console.log(blue(outputOptions.file) + ' ' + getSize(code))
} catch (e) {
console.error(e)
}
}
function getSize (code) {
return (Buffer.byteLength(code, 'utf8') / 1024).toFixed(2) + 'kb'
}
function blue (str) {
return '\x1b[1m\x1b[34m' + str + '\x1b[39m\x1b[22m'
}
build({
input: path.resolve(__dirname, 'src/index.js'),
plugins: [
resolve(),
commonjs(),
babel({ runtimeHelpers: true }),
replace({
'__VUE_LAZYLOAD_VERSION__': JSON.stringify(version)
}),
terser()
]
}, {
format: 'umd',
filename: 'vue-lazyload.js'
})
build({
input: path.resolve(__dirname, 'src/index.js'),
plugins: [
resolve(),
commonjs(),
replace({
'__VUE_LAZYLOAD_VERSION__': JSON.stringify(version)
}),
babel({ runtimeHelpers: true })
]
}, {
format: 'esm',
filename: 'vue-lazyload.esm.js'
})