如何在 React 中更改 index.html 的 path/file 名称?

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

当通过 npm build 构建 React(使用通常的 react-scripts/create-creact-app 等)应用程序时,我总是在 build/index.html.[=22 中获取入口文件=]

我试过将 src 移动到子文件夹中,但是 index.js 必须在 src/index.js 中。

那么如何更改index.html的输出路径?

即例如我想将它重命名为 index.htm,因为我有一个迂腐的怪癖,或者我想将输出路径更改为 build/srv/www/index.html?

(这些只是示例。)

要更改输出路径,您需要更改 webpack 配置,并且在 create-react-path 中是不可能的,除非您 运行 弹出脚本。

这样:

npm run eject

在 运行ning 之后,您将能够访问任何项目配置(在您的情况下是 webpack 配置),但您必须知道,一旦项目被弹出,您将无法返回。

更多信息在这里:

create-react-app