-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.dev.js
64 lines (53 loc) · 1.5 KB
/
rollup.dev.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
import * as rollup from "rollup";
import resolve from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import babel from "rollup-plugin-babel";
import serve from "rollup-plugin-serve";
const inputOptions = {
input: './src/main.js',
plugins: [
resolve({
jsnext: true,
main: true,
browser: true,
}),
commonjs(),
babel({
exclude: 'node_modules/**' // 只编译我们的源代码
}),
serve('../Biu')
]
};
const outputOptions = {
file: './build/bundle.js',
format: 'iife'
};
async function build() {
// create a bundle
const bundle = await rollup.rollup(inputOptions);
// generate code and a sourcemap
const { code, map } = await bundle.generate(outputOptions);
// or write the bundle to disk
await bundle.write(outputOptions);
}
build();
const watchOptions = {
...inputOptions,
output: [outputOptions],
watch: {
include:'src/**',
}
};
const watcher = rollup.watch(watchOptions);
watcher.on('event', event => {
console.log(event.code);
// event.code 会是下面其中一个:
// START — 监听器正在启动(重启)
// BUNDLE_START — 构建单个文件束
// BUNDLE_END — 完成文件束构建
// END — 完成所有文件束构建
// ERROR — 构建时遇到错误
// FATAL — 遇到无可修复的错误
});
// 停止监听
watcher.close();