-
Notifications
You must be signed in to change notification settings - Fork 189
/
bundle.js
executable file
·74 lines (65 loc) · 1.96 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
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
import webpack from 'webpack';
/**
* You can let webpack watch the files and rebundle on change, or you can do it
* via gulp. Gulp will probably be easier at first, since you have to configure
* multiple watches for the other src files as well.
*/
export default function createBundleTask({config = undefined, watch = false, logStats = false}) {
const compiler = webpack(config);
return function bundle(done) {
if (watch) {
compiler.watch({}, handleWebpackResult);
} else {
compiler.run(handleWebpackResult);
}
function handleWebpackResult(err, stats) {
if (err) {
console.error(err.stack || err);
if (err.details) {
console.error(err.details);
}
return;
}
const info = stats.toJson();
if (stats.hasErrors()) {
console.error(info.errors);
}
if (stats.hasWarnings()) {
console.warn(info.warnings);
}
if (logStats) {
console.log(stats.toString());
}
done();
}
};
}
export function getBabelLoaderOptions({optimize = false, transpileOnlyForLastChromes = false}) {
if (optimize || !transpileOnlyForLastChromes) {
return {
babelrc: false,
presets: [
['@babel/preset-env', {
useBuiltIns: 'usage',
modules: false
}]
]
};
}
return {
babelrc: false,
presets: [
['@babel/preset-env', {
useBuiltIns: 'usage',
targets: {
browsers: [
'>0.25%',
'not op_mini all'
]
}
}]
],
plugins: ['@babel/plugin-transform-spread'],
cacheDirectory: true
};
}