-
Notifications
You must be signed in to change notification settings - Fork 35
/
webpack.config.js
110 lines (104 loc) · 2.98 KB
/
webpack.config.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/**
* @license
* Copyright 2020 Google LLC.
* This code may only be used under the BSD style license found at
* http://polymer.github.io/LICENSE.txt
* Code distributed by Google as part of this project is also
* subject to an additional IP rights grant found at
* http://polymer.github.io/PATENTS.txt
*/
const path = require('path');
const webpack = require('webpack');
const TerserPlugin = require('terser-webpack-plugin');
const CircularDependencyPlugin = require('circular-dependency-plugin');
const lib = './shells/lib';
// Decrease MAX_CYCLES every time you eliminate circular dependencies from the codebase.
const MAX_CYCLES = 0;
let numCyclesDetected = 0;
const debugSettings = {
// debug settings
mode: 'none',
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
sourceMap: true,
parallel: true,
extractComments: true,
terserOptions: {
mangle: false
}
})
]
}
};
const performanceSettings = {
mode: 'production',
performance: {
hints: false
},
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
sourceMap: true,
parallel: true,
extractComments: true,
terserOptions: {
mangle: false
}
})
]
}
};
//const settings = performanceSettings;
const settings = debugSettings;
module.exports = {
...settings,
// all-purpose settings
devtool: 'source-map',
entry: {
worker: `${lib}/worker/src/worker.js`
},
output: {
filename: '[name].js',
path: path.resolve(__dirname, `${lib}/worker/dist`)
},
plugins: [
new webpack.NormalModuleReplacementPlugin(
// build/worker.js needs the node version of this file
/sourcemapped-stacktrace-web.js/,
resource => resource.request = resource.request.replace(/web/, `node`)
),
new webpack.NormalModuleReplacementPlugin(
// build/worker.js needs the stub version of this file
/devtools-channel-web.js/,
resource => resource.request = resource.request.replace(/web/, `stub`)
),
new CircularDependencyPlugin({
exclude: /node_modules/,
onStart() {
numCyclesDetected = 0;
},
onDetected({module, paths, compilation}) {
numCyclesDetected++;
compilation.warnings.push(new Error(paths.join(' -> ')));
},
onEnd({compilation}) {
if (numCyclesDetected > MAX_CYCLES) {
compilation.errors.push(new Error(
`cycle detection: ${numCyclesDetected} cycles exceeds configured limit of ${MAX_CYCLES}`
));
} else if (numCyclesDetected > 0) {
compilation.warnings.unshift(new Error(
`cycle detection: ${numCyclesDetected} cycles found (configured limit is ${MAX_CYCLES})`
));
}
},
allowAsyncCycles: false,
// failOnError should replace the onStart(), onDetected() and onEnd() methods
// once we we eliminate circular dependencies.
// failOnError: true,
})
]
};