-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodule.js
More file actions
86 lines (76 loc) · 1.59 KB
/
Copy pathmodule.js
File metadata and controls
86 lines (76 loc) · 1.59 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
import * as rollup from 'rollup';
import multiEntry from 'rollup-plugin-multi-entry';
import commonjs from 'rollup-plugin-commonjs';
import nodeResolve from 'rollup-plugin-node-resolve';
import localResolve from 'rollup-plugin-local-resolve';
import html from 'rollup-plugin-html';
import json from 'rollup-plugin-json';
const core = require ('fit-cli');
let options;
function build () {
// create a bundle
let develop = core.args.env() === 'develop';
if (develop) {
const eventHandler = (event) => {
switch (event.code) {
case 'BUNDLE_END':
console.log (`${event.input} bundled in ${event.duration}ms`.gray);
break;
case 'ERROR':
console.log (`error: ${event.error}`);
break;
}
};
try {
rollup.watch (options).on('event', eventHandler);
}
catch (e) {
core.utils.error ('rollup-bundle', e);
return false;
}
return;
}
else {
let bundle;
try {
bundle = rollup.rollup (options);
}
catch (e) {
core.utils.error ('rollup-bundle', e);
return false;
}
// generate code and a sourcemap
bundle.generate (options.output);
// or write the bundle to disk
bundle.write (options.output);
return;
}
}
export function init (config) {
options = {
input: config.source,
output: {
file: config.output,
format: 'iife'
},
plugins: [
multiEntry(),
nodeResolve ({
module: true,
browser: true,
jsnext: true,
main: true,
preferBuiltins: false
}),
localResolve(),
commonjs ({
include: 'node_modules/**',
ignoreGlobal: false,
sourceMap: false
}),
json(),
html()
]
};
return build();
}