【问题标题】:Deploy production of create-react-app to heroku without buildpacks在没有 buildpacks 的情况下将 create-react-app 的生产部署到 heroku
【发布时间】:2018-10-23 22:56:37
【问题描述】:

我想将使用 create-react-app 创建的 React 项目部署到 Heroku 服务器。

简单地推送到 Heroku 会导致应用部署在开发模式。

(也许 Heroku 需要 npm start 而不是 npm build?)

我不想使用任何构建包来解决这个问题。

配置 Heroku 以在生产环境中构建应用程序的实际操作方法是什么?

【问题讨论】:

  • 请添加一些代码,以便其他用户可以测试您所描述的内容。谢谢!
  • Heroku 不是普通的网络主机。它并非旨在盲目地提供您自己编译的静态资产。它旨在运行在部署期间使用 buildpack 构建的 Web 应用程序。 (它甚至不提供传统意义上的文件系统。)如果您只想将文件放到 Web 服务器上并提供服务,那么在其他地方寻找会更好。有很多服务。

标签: heroku create-react-app


【解决方案1】:

首先,在heroku cli中设置生产变量:

heroku config:set NODE_ENV=production

然后,只需将您的 package.json 脚本更改为即可:

 "scripts": {
       "heroku-prebuild": "npm install -g serve",
       "devstart": "react-scripts start",
       "start": "serve -s build",
       "build": "react-scripts build",
       "eject": "react-scripts eject",
 },

使用“heroku-prebuild”,您无需上传任何额外代码即可安装服务。

【讨论】:

    猜你喜欢
    • 2017-09-21
    • 2023-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-14
    • 2020-04-02
    • 2023-03-12
    相关资源
    最近更新 更多