通过create-react-app脚手架创建的react项目,默认是看不到webpack相关配置文件的。

如果你想针对webpack配置文件进行一些修改。就需要把webpack文件调出来。

通过

npm run eject

把webpack文件暴露出来,这个操作是不可逆的

  • npm run eject会修改package.json文件的scripts,里面的"eject"脚本会被删除,因为过程不可逆。

完整示例:

C02Z84E5LVCF:mm_h5test maomao$ npm run eject

> mm_h5test@0.1.0 eject /Users/maomao/Documents/demo/h5/mm_h5test
> react-scripts eject

NOTE: Create React App 2+ supports TypeScript, Sass, CSS Modules and more without ejecting: https://reactjs.org/blog/2018/10/01/create-react-app-v2.html

✔ Are you sure you want to eject? This action is permanent. … yes
This git repository has untracked files or uncommitted changes:

package.json
M src/index.js
package-lock.json
src/demo.module.css
src/demo.tsx
src/img/
src/react-app-env.d.ts
tsconfig.json

Remove untracked files, stash or commit any changes, and try again.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! mm_h5test@0.1.0 eject: `react-scripts eject`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the mm_h5test@0.1.0 eject script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/maomao/.npm/_logs/2021-05-20T01_50_09_352Z-debug.log
C02Z84E5LVCF:mm_h5test maomao$