-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathconfig-overrides.js
54 lines (51 loc) · 1.41 KB
/
config-overrides.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
/* eslint-disable @typescript-eslint/no-var-requires */
const webpack = require('webpack');
const CircularDependencyPlugin = require('circular-dependency-plugin');
const MAX_CYCLES = 5;
let numCyclesDetected = 0;
module.exports = function override(config) {
config.module.rules.unshift({
test: /\.worker\.ts$/,
use: {
loader: 'worker-loader',
},
});
config.resolve.fallback = {
crypto: require.resolve('crypto-browserify'),
buffer: require.resolve('buffer'),
stream: require.resolve('stream-browserify'),
process: false,
fs: false,
path: false,
};
config.plugins.push(
new webpack.ProvidePlugin({
process: 'process/browser',
Buffer: ['buffer', 'Buffer'],
}),
);
if (process.argv.includes('checkCycles')) {
config.plugins.push(
new CircularDependencyPlugin({
exclude: /node_modules/,
onStart() {
numCyclesDetected = 0;
},
onDetected({ paths, compilation }) {
numCyclesDetected++;
compilation.warnings.push(new Error(paths.join(' -> ')));
},
onEnd({ compilation }) {
if (numCyclesDetected > MAX_CYCLES) {
compilation.errors.push(
new Error(
`Detected ${numCyclesDetected} cycles which exceeds configured limit of ${MAX_CYCLES}`,
),
);
}
},
}),
);
}
return config;
};