-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
49 lines (42 loc) · 1.02 KB
/
gulpfile.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
const path = require('path')
const { rollup, watch: rollupWatch } = require('rollup')
const vuePlugin = require('rollup-plugin-vue')
const { terser } = require('rollup-plugin-terser')
const commonjs = require('@rollup/plugin-commonjs')
const nodeResolve = require('@rollup/plugin-node-resolve')
const entry = [path.join(__dirname, 'src/index.js')]
const inputOptions = {
input: entry,
plugins: [
vuePlugin(),
nodeResolve,
commonjs()
]
}
const outputOptions = {
format: 'iife',
dir: __dirname,
}
async function build() {
inputOptions.plugins.push(terser())
const bundle = await rollup(inputOptions)
await bundle.generate(outputOptions);
await bundle.write(outputOptions)
await bundle.close()
}
function watch() {
const watcher = rollupWatch({
...inputOptions,
output: outputOptions
})
watcher.on('event', (event) => {
if (event.error) {
console.error(event.error);
}
if (event.result) {
event.result.close();
}
});
}
exports.build = build
exports.watch = watch