如何通过 npm 更改 reactJs 引导中使用的默认配置文件 [英] How to change the default configuration files used in bootstrapping of reactJs through npm

查看:61
本文介绍了如何通过 npm 更改 reactJs 引导中使用的默认配置文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 create-react-app 命令创建了一个非常基本的 hello world reactJs 应用程序,该命令是 npm 的一部分.这是我作为应用程序模板的一部分获得的目录结构:

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:

我的 package.json 文件如下所示:

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"
  }
}

我观察到,每次我执行 npm run build 命令时,它都会使用 public 目录中的 index.htmlindex.html.js 存在于 src 目录中,以在 build 目录中创建最终的生产版本.我确信这是因为所有内部管道都通过 npm 发生.有人可以帮助我了解这是如何发生的,以及如何将这些目标文件更改为我自己的名为 HelloWorld.html(存在于 public 目录中)和 的自定义文件myApp.js(存在于 src 目录中)?

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)?

推荐答案

如果你想改变构建配置,你可以运行 npm run eject 这将从你的项目中删除构建依赖并添加配置文件添加到您的项目中,允许您根据需要更改它们.

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.

  • 注意,此操作为单程票,不可返回!

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

这篇关于如何通过 npm 更改 reactJs 引导中使用的默认配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆