一、 用于按需加载antd的组件(具体配置方式请参照官网https://ant.design/docs/react/use-with-create-react-app-cn,这里只对config-overrides.js文件说明)javascript
module.exports = override(
fixBabelImports('import', {
libraryName: 'antd',
libraryDirectory: 'es',
style: 'css'
})
);复制代码
补充: 若未使用customize-cra(对于react-app-rewired@2.x 如下版本):css
module.exports = function override(config, env) {
// do stuff with the webpack config...
config = injectBabelPlugin(
['import', [
{
libraryName: 'antd',
libraryDirectory: 'es',
style: 'css'
},
{
libraryName: 'antd-mobile',
libraryDirectory: 'es',
style: 'css'
}
]],
config
)
return config;
};复制代码
二、设置绝对路径:addWebpackAliasjava
module.exports = override(
addWebpackAlias({
["mock"]: path.resolve(__dirname, "src/mock"),
["containers"]: path.resolve(__dirname, "src/containers"),
["components"]: path.resolve(__dirname, "src/components")
})
)复制代码
三、配置less:addLessLoader (loaderOptions)react
module.exports = override(
addLessLoader({
javascriptEnabled: true,
modifyVars: {
'@primary-color': '#1DA57A'
}
})
);复制代码
结语:配置了几个经常使用的配置,后续会继续更新,代码 https://git.coding.net/sunqun/react-demo-app.gitwebpack