-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKarmaWebpack.js
82 lines (73 loc) · 1.67 KB
/
KarmaWebpack.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
75
76
77
78
79
80
81
82
/* eslint-disable */
const webpack = require('webpack');
const path = require('path');
class KarmaSyncPlugin {
constructor(options) {
this.karmaEmitter = options.karmaEmitter;
}
apply(compiler) {
compiler.hooks.done.tap('KarmaSyncPlugin', stats => {
console.log(stats.toString({
chunks: false, // Makes the build much quieter
colors: true // Shows colors in the console
}));
// all files are avaliable via stats.toJson().assets
this.notifyKarmaAboutChanges();
});
}
notifyKarmaAboutChanges() {
// this.karmaEmitter.refreshFiles();
}
}
const webpackOptions = {
mode: 'development',
entry: {
one: path.resolve(__dirname) + '/foo-one.js',
two: path.resolve(__dirname) + '/foo-two.js',
},
output: {
filename: '[name].bundle.js',
path: path.resolve(__dirname) + '/dist',
},
plugins: [
new KarmaSyncPlugin({ karmaEmitter: true })
],
optimization: {
splitChunks: {
chunks: 'all',
minSize: 0,
cacheGroups: {
commons: {
name: 'commons',
chunks: 'initial',
minChunks: 2,
},
},
},
},
};
class KarmaWebpack {
constructor() {
this.bundle();
}
bundle() {
const compiler = webpack(webpackOptions);
compiler.run((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);
}
});
}
}
new KarmaWebpack();