如何为使用 create-react-app 创建的 React 项目更新 webpack 配置?
问题描述:
我使用 create-react-app 创建了一个 React 项目.现在我需要更新 webpack 配置,但我在任何地方都找不到该文件.我需要自己创建这个文件还是过程是什么?我刚开始反应,不确定如何从这里开始.
I have created a react project using create-react-app. Now I need to update the webpack config, but I don't find the file anywhere. Do I need to create this file myself or what is the process? I am new to react and not really sure how to proceed from here.
答
无需运行npm run eject
第一步
npm install react-app-rewired --save-dev
第 2 步
将 config-overrides.js
添加到项目根目录.(不是 ./src)
Add config-overrides.js
to the project root directory.(NOT ./src)
// config-overrides.js
module.exports = function override(config, env) {
// New config, e.g. config.plugins.push...
return config
}
步骤 3
重新启动您的应用.完成
Restart your app. Done