generated from little-buddy/craco-react-webapp-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
craco.config.js
84 lines (77 loc) · 1.83 KB
/
craco.config.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
/* eslint-disable @typescript-eslint/no-var-requires */
const { when } = require('@craco/craco');
const webpack = require('webpack');
const WebpackBundleAnalyzer =
require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const StyleLintPlugin = require('stylelint-webpack-plugin');
const WepbackBar = require('webpackbar');
const Smp = require('speed-measure-webpack-plugin');
const HardSourceWebpackPlugin = require('hard-source-webpack-plugin');
const {
isEnvProduction,
addPath,
splitChunks,
getBabelConf,
refactorEntry,
isAnalyze,
} = require('./cracoplugin');
/*
carco 的 babel 只能在 carco.config.js 里面配置
*/
/*
carco.config.js 不保证只加载一次
see https://github.com/dilanx/craco/issues/518
*/
module.exports = () => {
console.log(addPath('./src'));
return {
// 自定义 fork 的react-scripts 路径
// reactScriptsVersion:''
webpack: new Smp().wrap({
configure: (config, { env, paths }) => {
refactorEntry(config);
// eslint-disable-next-line no-unused-expressions
isEnvProduction && splitChunks(config);
return config;
},
plugins: [
new WepbackBar({
profile: true,
color: '#fa8c16',
}),
// new HardSourceWebpackPlugin(),
new webpack.ContextReplacementPlugin(/moment[/\\]locale$/, /zh-cn/),
// 默认处理['css', 'scss', 'sass']
// new StyleLintPlugin(),
...when(isAnalyze, () => [new WebpackBundleAnalyzer()], []),
],
babel: getBabelConf(),
style: {
postcss: {
mode: 'file',
},
},
eslint: {
mode: 'file',
},
externals: {
// cdn 资源不打包
},
alias: {
'@': addPath('./src'),
},
}),
devServer: {
proxy: {
'/api': {
target: 'https://radishes.vercel.app',
secure: false,
changeOrigin: true,
pathRewrite: {
'^/api': '/api',
},
},
},
},
};
};