-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbundle.js
43 lines (37 loc) · 1.21 KB
/
bundle.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
/*eslint-env node*/ /*globals*/
"use strict";
const rollup = require("rollup");
module.exports = function init({ watcher = null, livereload = null } = {}) {
return function (config) {
if (!config) {
throw new Error("Argument 'config' is required.");
}
if (!config.dest) {
throw new Error("Argument 'config.dest' is required.");
}
if (!config.entry) {
throw new Error("Argument 'config.entry' is required.");
}
if (!config.moduleName) {
throw new Error("Argument 'config.moduleName' is required.");
}
if (watcher) {
watcher.on("change", (module, id) => {
if (config.moduleName !== module) { return; }
console.log("Module changed", module, id);
bundle();
});
}
function bundle() {
return rollup.rollup(config).then((bundler) => {
console.log(`Bundled module '${config.moduleName}'`);
bundler.modules.forEach(module => console.log(` <- ${module.id}`));
console.log(` -> ${config.dest}`);
bundler.write(config);
livereload && livereload.notify(config.dest);
}).catch((err) => console.log("error", err));
}
bundle();
return livereload && livereload.notify("/");
};
};