如何将Create-React-App构建推送到Heroku?

时间:2016-11-03 19:26:05

标签: javascript reactjs heroku webpack redux

过去,我只使用github的GH-Pages上传我的前端应用程序作为静态版本。这是我的第一个React应用程序,它连接到我在Heroku上传和运行的后端API。

我使用Create-React-App在反应中构建这个应用程序。当我命令npm run build ... Webpack构建我的es5版本的代码,以便浏览器可以读取它。所以我的问题是,这是我第一次在heroku上传一个前端应用程序,我该怎么做我的反应文件?

由于

1 个答案:

答案 0 :(得分:4)

有一个buildpack,允许你部署到heroku而无需配置!请参阅Mars Hall关于该主题的博客文章https://blog.heroku.com/deploying-react-with-zero-configuration

在博客上,您将找到有关将新的create-react-app部署到heroku的说明,但是要为预先存在的项目执行此操作...

cd到终端的项目文件夹并输入以下内容

git init 

heroku create YOURPROJECTNAME --buildpack https:/github.com/mars/create-react-app-buildpack.git 
// (creates the heroku project with the create-react-app buildpack specified)

git add . 

git commit -m "YOUR COMMENTS" 

git push heroku master 

heroku open