-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig-overrides.js
133 lines (120 loc) · 3.87 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
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
const webpack = require('webpack');
const path = require('path');
const fs = require('fs');
const git = require('git-rev-sync');
const CircularDependencyPlugin = require('circular-dependency-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin');
const isProduction = process.env.NODE_ENV === 'production';
const { addMultipleEntry, addLessLoader, modifyVars } = require('./config-overrides.util');
const { entries } = require('./config-overrides.projects');
const {
override,
addBundleVisualizer,
addWebpackPlugin,
addWebpackResolve,
addWebpackAlias,
addDecoratorsLegacy,
fixBabelImports,
overrideDevServer,
watchAll,
} = require('customize-cra');
module.exports = {
webpack: override(
addDecoratorsLegacy(),
fixBabelImports('antd', {
libraryName: 'antd',
libraryDirectory: 'es',
style: true,
}),
addLessLoader({
cssLoaderOptions: {},
cssModules: { mode: 'local' },
lessOptions: {
math: 'parens-division',
javascriptEnabled: true,
sourceMap: true,
modifyVars: modifyVars,
},
}),
addMultipleEntry(entries),
addWebpackAlias({
'~': path.resolve(__dirname, 'src/'),
'@': path.resolve(__dirname, 'src/'),
'src': path.resolve(__dirname, 'src/'),
'locale': path.resolve(__dirname, 'src/locale'),
'root': path.resolve(__dirname, 'src/'),
}),
addWebpackResolve({
fallback: {
https: false,
http: false,
url: false,
os: false,
assert: require.resolve('assert/'),
stream: require.resolve('stream-browserify'),
buffer: require.resolve('buffer'),
},
extensions: ['.ts', '.tsx', '.js', '.jsx', '.less', '.css', '.json', '.svg'],
}),
addWebpackPlugin(
new webpack.ProvidePlugin({
Buffer: ['buffer', 'Buffer'],
})
),
config => {
const headScripts = [`<meta name="gitcommit" content="${git.long()}" />`].join('\n');
const tsJSONPath = path.resolve(__dirname, 'tsconfig.json');
const tsJson = JSON.parse(fs.readFileSync(tsJSONPath, 'UTF8'));
tsJson.compilerOptions.paths = {
'~/*': ['src/*'],
'@/*': ['src/*'],
'locale/*': ['src/locale/*'],
};
tsJson.compilerOptions.baseUrl = 'src';
fs.writeFileSync(tsJSONPath, JSON.stringify(tsJson, null, 2));
let _env = process.env.AppEnv || 'local';
if (!isProduction) {
config.plugins.push(
new CircularDependencyPlugin({
// exclude detection of files based on a RegExp
exclude: /node_modules/,
// add errors to webpack instead of warnings
failOnError: true,
// set the current working directory for displaying module paths
cwd: process.cwd(),
})
);
}
config.plugins.push(
new InterpolateHtmlPlugin(HtmlWebpackPlugin, {
REACT_APP_GIT_COMMIT: JSON.stringify(git.long()),
}),
new webpack.DefinePlugin({
'process.env.ENV_NAME': JSON.stringify(_env),
'process.env.LANGUAGE': JSON.stringify(process.env.LANGUAGE),
})
);
// Object.keys(dllWebpacks.entry).forEach(name => {
// config.plugins.push(new webpack.DllReferencePlugin({
// context: path.join(__dirname),
// manifest: require(`./public/dll/${name}-manifest.json`), // eslint-disable-line
// }));
// })
config.plugins.forEach(element => {
if (element.constructor.name === 'HtmlWebpackPlugin') {
element.userOptions.HEAD_SCRIPTS = headScripts;
}
});
return config;
}
),
devServer: overrideDevServer(config => {
return {
...config,
historyApiFallback: {
// rewrites: [{ from: /^\/v2/, to: '/dds2.html' }],
},
};
}),
};