-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconfig-overrides.js
More file actions
84 lines (82 loc) · 2.38 KB
/
config-overrides.js
File metadata and controls
84 lines (82 loc) · 2.38 KB
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
const {
override,
overrideDevServer,
addLessLoader,
fixBabelImports,
addBundleVisualizer,
removeModuleScopePlugin,
disableEsLint,
addBabelPlugin,
addWebpackModuleRule,
useEslintRc,
addWebpackAlias,
} = require('customize-cra');
const ForkTsCheckerWebpackPlugin = require('react-dev-utils/ForkTsCheckerWebpackPlugin');
const fs = require('fs');
const path = require('path');
const mockMiddleware = require('./mockMiddleware');
const projectConfigOverrides = {};
try {
const customConfigOverrides = require(path.resolve(
fs.realpathSync(process.cwd()),
'./config-overrides',
));
if (typeof customConfigOverrides === 'function')
projectConfigOverrides.webpack = customConfigOverrides;
else Object.assign(projectConfigOverrides, customConfigOverrides);
} catch (error) {
//
}
module.exports = {
webpack: override(
addLessLoader({
javascriptEnabled: true,
}),
fixBabelImports('antd', {
style: true,
libraryDirectory: 'es',
}),
addBundleVisualizer({}, true),
removeModuleScopePlugin(),
addWebpackAlias({ '@/': './src' }),
process.env.NODE_ENV === 'development' && addBabelPlugin('react-hot-loader/babel'),
useEslintRc(),
(config, env) => {
// eslint resolvePluginsRelativeTo
const eslintRule = config.module.rules.filter(
r => r.use && r.use.some(u => u.options && u.options.useEslintrc !== void 0),
)[0];
if (eslintRule) delete eslintRule.use[0].options.resolvePluginsRelativeTo;
return config;
},
process.env.NODE_ENV === 'production' && disableEsLint(),
process.env.NODE_ENV === 'production' &&
(config => {
const ts = config.plugins.findIndex(item => item instanceof ForkTsCheckerWebpackPlugin);
if (ts !== -1) {
config.plugins.splice(ts, 1);
}
// process.exit();
return config;
}),
addWebpackModuleRule({
test: /\.js/,
include: /node_modules(?:\/|\\)react-dom/,
use: ['react-hot-loader/webpack'],
}),
projectConfigOverrides.webpack,
),
devServer: override(
overrideDevServer(config => {
const { before } = config;
config.before = (app, server) => {
mockMiddleware(app);
before(app, server);
};
return config;
}),
projectConfigOverrides.devServer,
),
jest: projectConfigOverrides.jest,
paths: projectConfigOverrides.paths,
};