Gulp将Node应用程序的dist文件夹部署到Heroku [英] Gulp deploy dist folder of Node app to Heroku

查看:73
本文介绍了Gulp将Node应用程序的dist文件夹部署到Heroku的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Node,git,github和Heroku的新手,我正在努力找到将应用程序发送到Heroku的最佳方法,而又不会用我编译后的,缩小的应用程序弄乱仓库,也不会做太多事情Heroku.

I'm reasonably new to node, git, github and Heroku and I'm struggling to work out the best way of sending my application to Heroku without cluttering up the repo with my compiled, minified app and without doing too much in Heroku.

我的node.js项目看起来像这样:

My node.js project looks a bit like this:

- client
     ... code
- server
     ... code
- node_modules
- package.json
- gulpfile.js
- dist
    - client
    - server

除了node_modulesdist之外的所有内容都进入了github.

Everything apart from node_modules and dist goes into github.

gulpfile编译,最小化和连接准备在dist中发布的所有内容. 我如何只将dist文件夹推送到Heroku,而又不将其放入github?什么是最佳做法?我不希望将gulpfile发送到Heroku,因为这意味着将package.json中的devDependencies移到了并使用后期更新脚本,因为它将项目与Heroku的联系比我想要的更多.

The gulpfile compiles, minifies and concatenates everything ready for release in dist. How do I push just the dist folder to Heroku, without also putting it into github? What is best practice? I'd rather not send my gulpfile to Heroku as it means moving the devDependencies in package.json and using a post update script, as it ties the project to Heroku more than I'd like.

这两个帖子总结了不使用帖子挂钩的原因: https://stackoverflow.com/a/15050864/344022 & https://stackoverflow.com/a/21056644/344022 ,很遗憾,它们没有提供易于理解的替代方法.

Reasons for not using post hook are summed up well in these two posts: https://stackoverflow.com/a/15050864/344022 & https://stackoverflow.com/a/21056644/344022, unfortunately they don't provide an easy to understand alternative.

推荐答案

Heroku现在正在开发中的静态buildpack可以处理此问题(请参见

Heroku now has a static buildpack in development to handle this (see https://github.com/heroku/heroku-buildpack-static)

{
  "root": "dist/",
  "clean_urls": true,
  "routes": {
      "/**": "index.html"
  }
}

扩展package.json脚本以确保构建了dist/目录,例如

"scripts": {
  ...
  "heroku-postbuild": "gulp"
}

这样就可以安装来自package.json的开发依赖项

heroku config:set NPM_CONFIG_PRODUCTION=false --app

多个构建包,因此您可以构建和部署

heroku buildpacks:add heroku/nodejs --app <app_name>
heroku buildpacks:add https://github.com/heroku/heroku-buildpack-static.git --app <app_name>

在这种情况下,您的procfile可以为空.

Your procfile can be empty in this case.

这篇关于Gulp将Node应用程序的dist文件夹部署到Heroku的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆