如何在create-react-app项目中重命名index.html? [英] How can I rename index.html in a create-react-app project?

查看:773
本文介绍了如何在create-react-app项目中重命名index.html?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Surge托管我的create-react-app网站,并且要与之一起使用客户端路由,您需要将进入点设置为200.html,但是在使用create-react-app时,默认情况下到index.html.在不破坏网站的情况下重命名该文件的最佳方法是什么?

I'm using Surge to host my create-react-app website and in order to use client-side routing with it you need your entry point to be 200.html but when using create-react-app it's by default set to index.html. What's the best way to rename that file without breaking the website?

推荐答案

如相关 CRA问题1761 提出的解决方案是弹出整个配置(包括Webpack):

As suggest in related CRA issue 1761 the proposed solution is to eject entire configuration (including Webpack):

npm run eject

运行npm run exit将所有配置文件和传递依赖项(Webpack,Babel,ESLint等)直接复制到您的项目中,以便您可以完全控制它们.像npm start和npm run build这样的命令仍然可以使用,但是它们将指向复制的脚本,因此您可以对其进行调整.至此,您就可以依靠自己了. (为什么我喜欢创建React App)

弹出后,您将可以在config/webpack.*.js中手动编辑配置.

After ejecting you will be able to manually edit configuration inside config/webpack.*.js.

您可能会期望像这样的行:

You may expect there line like:

new HtmlWebpackPlugin({ inject: true, template: paths.appHtml, filename: 'index.html', ...)

只需将index.html替换为所需的200.html.

也有可能使用构建命令(例如建议的

There is also a possibility to play around with building commands (like suggested lcoder):

{
  "scripts": {
    ...
    "build": "node scripts/build.js && mv build/index.html build/app.html",
    ...
  }
}

假设在build处理之后进行简单的重命名就足够了.

Assuming that simple rename after build process would be sufficient for you.

这篇关于如何在create-react-app项目中重命名index.html?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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