gpt4 book ai didi

javascript - 如何通过 npm 更改用于引导 reactJs 的默认配置文件

转载 作者:行者123 更新时间:2023-11-29 23:46:33 25 4
gpt4 key购买 nike

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

enter image description here

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

{
"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.html 中的 index.html。 js 出现在 src 目录中,以在 build 目录中创建最终的生产版本。我确信这是因为所有内部管道都是通过 npm 发生的。有人能帮我理解这是怎么发生的吗?我怎样才能将这些目标文件更改为我自己的名为 HelloWorld.html(位于 public 目录中)和 的自定义文件myApp.js(存在于 src 目录中)?

最佳答案

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

  • 请注意,此操作是单程票,您无法返回!

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

关于javascript - 如何通过 npm 更改用于引导 reactJs 的默认配置文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43797225/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com