How to change the default configuration files used in bootstrapping of reactJs through npm

ε祈祈猫儿з 提交于 2019-12-11 02:22:41

问题


I've created a very basic hello world reactJs application using create-react-app command which is part of npm. Here is the directory structure which I get as part of the application template:

My package.json file looks like this:

{
  "name": "hello-world",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "react": "^15.4.2",
    "react-dom": "^15.4.2"
  },
  "devDependencies": {
    "react-scripts": "0.9.5"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
  }
}

I observe that every time I perform npm run build command it uses index.html present in public directory and index.js present in src directory to create the final production build in build directory. I'm sure this is happening because of all the internal plumbing happening through npm. Can someone help me understand how this is happening and how can I change these targeted files to my own custom files named HelloWorld.html (present in public directory) and myApp.js (present in src directory)?


回答1:


If you want to change the build configuration you can run npm run eject which will remove the build dependency from your project and will add configuration files to your project, allowing you to change them as you need.

  • Note that this operation is a one way ticket, you can't go back!

https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#npm-run-eject



来源:https://stackoverflow.com/questions/43797225/how-to-change-the-default-configuration-files-used-in-bootstrapping-of-reactjs-t

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!