create-react-app为啥没有webpack配置文件?

create-react-app为啥没有webpack配置文件,想要修改怎么办。

阅读 15.8k
5 个回答

npm run eject

见官方文档

默认配置文件都是隐藏的,如果要自定义,运行npm run eject

Converting to a Custom Setup

If you’re a power user and you aren’t happy with the default
configuration, you can “eject” from the tool and use it as a
boilerplate generator.

Running npm run eject copies all the configuration files and the
transitive dependencies (Webpack, Babel, ESLint, etc) right into your
project so you have full control over them. Commands like npm start
and npm run build will still work, but they will point to the copied
scripts so you can tweak them. At this point, you’re on your own.

Note: this is a one-way operation. Once you eject, you can’t go back!

You don’t have to ever use eject. The curated feature set is suitable
for small and middle deployments, and you shouldn’t feel obligated to
use this feature. However we understand that this tool wouldn’t be
useful if you couldn’t customize it when you are ready for it.

点开package.json文件,可看到配置的命令是以 "react-scripts *" 来执行,所以打开node_modules文件夹,找到react-scripts文件夹进去, config目录即是你需要找的webpack的配置文件,然后就自己去修改配置就好

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题