-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathconfig-overrides.js
83 lines (73 loc) · 2.4 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
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
const path = require('path');
const babelConfig = require('./.babelrc');
const getBabelLoader = (config) => {
const babelLoaderFilter = (rule) =>
rule.loader && rule.loader.includes('babel') && rule.options && rule.options.plugins;
let loaders = config.module.rules.find((rule) => Array.isArray(rule.oneOf)).oneOf;
let babelLoader = loaders.find(babelLoaderFilter);
if (!babelLoader) {
loaders = loaders.reduce((ldrs, rule) => ldrs.concat(rule.use || []), []);
babelLoader = loaders.find(babelLoaderFilter);
}
return babelLoader;
};
const disableEslint = (config) => {
config.plugins = config.plugins.filter((el) => !(el && el.options && el.options.eslintPath));
};
module.exports = {
webpack(config, env) {
const {
module: { rules },
} = config;
disableEslint(config);
const assetLoaders = rules[rules.length - 1].oneOf;
const babelLoader = getBabelLoader(config);
delete babelLoader.options.presets;
delete babelLoader.options.plugins;
babelLoader.options.babelrc = true;
babelLoader.include = [babelLoader.include, path.resolve(__dirname, 'common')];
// throw 1;
config.resolve.plugins.splice(
config.resolve.plugins.indexOf(
config.resolve.plugins.find((el) => el.constructor.name === 'ModuleScopePlugin'),
),
1,
);
rules.unshift(
{
test: /\.(vert|frag)$/,
use: { loader: 'raw-loader' },
},
{
test: /\.worker-loader\.js$/,
use: { loader: 'worker-loader' },
},
);
config.output = {
...config.output,
globalObject: 'this',
};
assetLoaders
.find((loader) => loader.test.toString().includes('module\\.css'))
.use.splice(1, 0, '@teamsupercell/typings-for-css-modules-loader');
assetLoaders[assetLoaders.length - 1].exclude.push(/\.vert$/, /\.frag$/);
if (env === 'production') {
config.mode = 'development';
config.optimization.minimize = false;
config.plugins[0].options.minify.minifyJS = false;
}
return config;
},
devServer(configFunction) {
return function (proxy, allowedHost) {
const config = configFunction(proxy, allowedHost);
config.headers = {
'X-Frame-Options': 'Deny',
'Cross-Origin-Embedder-Policy': 'require-corp',
'Cross-Origin-Opener-Policy': 'same-origin',
};
return config;
};
},
};
module.exports.disableEslint = disableEslint;