有没有办法让 `react-scripts` 在构建的根目录中包含额外的文件?

Is there a way to have `react-scripts` include extra files in the root of the build?

我的情况:

我正在托管使用 create-react-app 在 Surge 上创建的应用程序。为了让 Surge 让 react-router 处理路由,我必须向根添加一个 200.html,为了处理 404,我必须向根添加一个 404.html。问题是,对于 npm run build,只有 index.htmlfavicon.ico 被添加到构建目录的根目录中。

可能的解决方案:

我可以通过在package.json中制作build脚本来复制其他文件react-scripts build && cp 200.html 404.html build

问题:

有没有更好的方法让 react-scripts 添加额外的文件到构建的根目录,而不是依赖 package.json 中的 bash 脚本?

我确定的答案是在我的 package.json 中使用 bash 脚本,正如我最初怀疑的那样,但我决定在部署脚本而不是构建脚本中执行文件操作,并且将 index.html 重命名为 200.html 而不是复制额外的文件,as suggested by the create-react-app docs;

"build": "react-scripts build",
"deploy": "npm run build && mv build/index.html build/200.html && surge build mydomain.com"

我认为在部署脚本而不是构建脚本中执行文件操作是正确的解决方案,因为该更改对于部署环境而言是独一无二的,这意味着,如果我在 surge 以外的地方进行部署,我可能不会想重命名索引文件。

如果有人有更好的建议,仍然欢迎其他解决方案。