简体   繁体   English

如何在React中更改index.html的路径/文件名?

[英]How can I change the path/file name of index.html in React?

When building a React (with usual react-scripts / create-creact-app etc.) app via npm build , I always get the entry file in build/index.html . 当通过npm build构建一个React(带有通常的react-scripts / create-creact-app等)应用时,我总是在build/index.html获得入口文件。

I've tried moving the src into a subfolder, but the index.js is required to be there in src/index.js . 我试过将src移到子文件夹中,但index.js必须在src/index.js

So how can I change the output path of the index.html ? 那么, 如何更改index.html的输出路径?

Ie eg I want to rename it to index.htm , because I am have a pedantic quirk, or I want to change the output path to build/srv/www/index.html ? 即例如我想将其重命名为index.htm ,因为我有一个古怪的怪癖,或者我想将输出路径更改为build/srv/www/index.html

(These are just examples.) (这些只是示例。)

To change the output path you need to change the webpack config, and in create-react-path is not possible unless you run the eject script. 要更改输出路径,您需要更改webpack配置,并且除非您运行弹出脚本,否则在create-react-path中是不可能的。

This way: 这条路:

npm run eject

After running it, you will be able to access to any project configuration (webpack config in your case), but you must know, once the project is ejected, you can't go back. 运行它之后,您将可以访问任何项目配置(您的情况下为webpack config),但是必须知道,一旦项目退出,就无法返回。

More information here: 此处的更多信息:

create-react-app 创建反应应用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我无法修复 Heroku“找不到所需的文件,名称:index.html”错误 - I can't fix Heroku "Could not find a required file, Name: index.html" error 无法将 React index.html 文件提供给 NodeJS 服务器 - Can't feed React index.html file to NodeJS server 如何使用gulp-inject将文件的内容插入到index.html中? - How can I insert the contents of a file in my index.html with gulp-inject? 如何将ReactJS应用程序(文件)编译成一个index.html文件? - How can I compile a ReactJS application (files) into one index.html file? 如何在index.html中指定构建编译指示? - How can I specify build pragmas in index.html? 使用webpack时如何移动“index.html”? - How can I move “index.html” when using webpack? “找不到所需的文件。名称:index.html”在 Heroku 上部署 React 应用程序时出错 - "Could not find a required file. Name: index.html" Error When Deploying React App on Heroku 找不到所需的文件。 名称:index.html 与 docker compose 反应 - Could not find a required file. Name: index.html in react with docker compose 找不到所需的文件。 名称:index.html - Could not find a required file. Name: index.html 如果没有 index.html,如何在 index.html 中运行脚本 - How to run scripts in index.html in react if you don't have index.html
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM