目的:webpack打包时将资源文件copy到指定路径
1:安装依赖copy-webpack-plugin、customize-cra、react-app-rewired
2:修改script,使用react-app-rewired命令
"build:copy": "cross-env NODE_ENV=production GENERATE_SOURCEMAP=false react-app-rewired --max-old-space-size=8192 build",
3:配置config-overrides.js
const { override, fixBabelImports } = require('customize-cra');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const copyFileConfig= ()=>(config, env)=>{
config.plugins.push(
new CopyWebpackPlugin(
[
{
from: 'assets/sample.csv',
to: 'assets/sample.csv'
}
])
);
return config;
}
module.exports = override(
copyFileConfig(),
//这里是antd的示例,与本主题无关
fixBabelImports('import', {
libraryName: 'antd',
libraryDirectory: 'es',
style: 'css',
}),
);
4:打包时执行npm run build:copy即可
标签:const,app,webpack,React,Webpack,build,copy,config From: https://www.cnblogs.com/Andy1982/p/16940564.html