-
Notifications
You must be signed in to change notification settings - Fork 11
/
config-overrides.js
121 lines (114 loc) · 3.56 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
/* eslint-disable */
const {
override,
fixBabelImports,
addLessLoader,
// addBundleVisualizer ,
} = require('customize-cra');
const paths = require('react-scripts/config/paths');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const WorkboxWebpackPlugin = require('workbox-webpack-plugin');
paths.appIndexJs = `${paths.appSrc}/pages/index.js`;
// paths.appLoginJs = `${paths.appSrc}/pages/login.js`;
paths.servedPath = './';
const getEntryConfig = env => {
const arr = 'development' === env ? [require.resolve('react-dev-utils/webpackHotDevClient')] : [];
return entry => {
return [...arr, `${paths.appSrc}/pages/${entry}.js`];
};
};
const removePlugin = (plugins, name) => {
const list = plugins.filter(it => !(it.constructor && it.constructor.name && name === it.constructor.name));
if (list.length === plugins.length) {
throw new Error(`Can not found plugin: ${name}.`);
}
return list;
};
const genHtmlWebpackPlugin = env => {
const minify = {
removeComments: true,
collapseWhitespace: true,
removeRedundantAttributes: true,
useShortDoctype: true,
removeEmptyAttributes: true,
removeStyleLinkTypeAttributes: true,
keepClosingSlash: true,
minifyJS: {
comments: '@cc_on',
},
minifyCSS: true,
minifyURLs: true,
};
const config = Object.assign(
{},
{ inject: true, template: paths.appHtml },
'development' !== env ? { minify } : undefined,
);
return entry => {
return new HtmlWebpackPlugin({
...config,
chunks: ['vendors', `runtime~${entry}.html`, entry],
filename: `${entry}.html`,
});
};
};
const supportMultiPage = (config, env) => {
const list = ['index', 'login'];
config.entry = {};
config.plugins = removePlugin(config.plugins, 'HtmlWebpackPlugin');
const getEntry = getEntryConfig(env);
const getHtmlWebpackPlugin = genHtmlWebpackPlugin(env);
list.forEach(it => {
config.entry[it] = getEntry(it);
config.plugins.push(getHtmlWebpackPlugin(it));
});
if ('development' === env) {
config.output.filename = 'static/js/[name].bundle.js';
} else {
config.plugins = removePlugin(config.plugins, 'GenerateSW');
const workboxWebpackPlugin = new WorkboxWebpackPlugin.GenerateSW({
clientsClaim: true,
exclude: [/\.map$/, /asset-manifest\.json$/, /\.html$/],
importWorkboxFrom: 'local',
// navigateFallback: paths.servedPath + '/index.html',
// navigateFallbackBlacklist: [
// // Exclude URLs starting with /_, as they're likely an API call
// new RegExp('^/_'),
// // Exclude URLs containing a dot, as they're likely a resource in
// // public/ and not a SPA route
// new RegExp('/[^/]+\\.[^/]+$'),
// ],
});
config.plugins.push(workboxWebpackPlugin);
}
return config;
};
module.exports = {
webpack: override(
supportMultiPage,
fixBabelImports('import', {
libraryName: 'antd',
libraryDirectory: 'es',
style: true,
}),
fixBabelImports('ant-design-pro', {
libraryName: 'ant-design-pro',
libraryDirectory: 'lib',
style: true,
camel2DashComponentName: false,
}),
addLessLoader({
javascriptEnabled: true,
localIdentName: '[local]--[hash:base64:5]',
// modifyVars: { '@primary-color': '#1DA57A' },
}),
// addBundleVisualizer(),
),
devServer: configFunction => {
return (proxy, allowedHost) => {
const config = configFunction(proxy, allowedHost);
config.historyApiFallback.rewrites = [{ from: /^\/login\.html/, to: '/build/login.html' }];
return config;
};
},
};