【发布时间】:2021-07-21 07:13:59
【问题描述】:
我正在使用 react-app-rewired 和 customize-cra 来设置一个带有共享 TypeScript 代码的多项目 monorepo,而不会从 create-react-app 中弹出(该设置在 this answer 中进行了描述)。布局如下:
/my-project
|--- /frontend <-Contains the create-react-app
|--- /shared <-Contains some typescript source, used by the CRA
...
它在本地工作得很好。我唯一不知道的是如何将它部署到 Heroku:
- 如果我使用 Git 只推送 'frontend' 子目录 (
git subtree push --prefix frontend heroku master),Heroku 构建当然会失败,因为它无法在 /shared 中找到源文件——那些甚至没有推送到服务器。 - 我尝试使用monorepo buildpack,如here 所述,但结果相同。构建失败,在 /shared 中找不到源文件。
- 我已经尝试了评论here中的“hacky”解决方案:在package.json中设置
"postinstall": "npm install --prefix frontend。尽管它似乎已构建,但访问 https://myap123.herokuapp.com 和 https://myap123.herokuapp.com/frontend 会产生 404。 - 我还尝试了评论here中的解决方案:将
release: cd frontend && npm install && npm run build放入procfile中。相同的行为:它似乎已构建,但无法从浏览器访问 (404)。
虽然有很多关于从 monorepo 部署项目的资源,以及关于在 React 和 Node 项目之间共享代码的许多其他资源,但我一直找不到任何对两者都有效的东西:共享代码、和 将引用该代码的项目部署到 Heroku。此时,我只专注于尝试部署前端。
任何帮助将不胜感激。
【问题讨论】:
标签: reactjs heroku create-react-app monorepo