咕噜和凉亭heroku上

今天我想将我的node.js应用程序部署到heroku。 当地我正在使用bowergrunt发展也我想仍然使用它们。

现在,按照我在networking上发现的一些build议,我将bower添加到了我的dependencies并添加了"postinstall": "node_modules/.bin/bower install到我的package.json postinstall

现在我有一些grunt问题。 当我把我的grunt依赖从devDependencies移到dependenciesgrunt不能识别我的tasks ,例如当我有

  { "name": "js-linkedin-connector", "version": "0.1.0", "dependencies": { "passport": "~0.1.17", "passport-local": "~0.1.6", "passport-linkedin-oauth2": "~1.0.1", "connect": "~2.11.0", "underscore": "~1.5.2", "bower": "1.2.x", "grunt": "~0.4.1", "grunt-cli": "0.1.11", "load-grunt-tasks": "~0.1.0", "grunt-contrib-copy": "~0.4.1", "grunt-contrib-concat": "~0.3.0", "grunt-contrib-coffee": "~0.7.0", "grunt-contrib-uglify": "~0.2.0", "grunt-contrib-compass": "~0.5.0", "grunt-contrib-jshint": "~0.6.0", "grunt-contrib-cssmin": "~0.6.0", "grunt-contrib-connect": "~0.5.0", "grunt-contrib-clean": "~0.5.0", "grunt-contrib-htmlmin": "~0.1.3", "grunt-contrib-watch": "~0.5.2", "grunt-autoprefixer": "~0.2.0", "grunt-usemin": "~2.0.0", "grunt-svgmin": "~0.2.0", "grunt-rev": "~0.1.0", "grunt-concurrent": "~0.3.0", "grunt-jasmine-node": "~0.1.0", "grunt-google-cdn": "~0.2.0", "grunt-ngmin": "~0.0.2", "time-grunt": "~0.1.0", "grunt-karma": "~0.6.2", "connect-livereload": "~0.3.0" }, "devDependencies": { "karma-ng-scenario": "~0.1.0", "karma-script-launcher": "~0.1.0", "karma-chrome-launcher": "~0.1.0", "karma-firefox-launcher": "~0.1.0", "karma-html2js-preprocessor": "~0.1.0", "karma-jasmine": "~0.1.3", "karma-requirejs": "~0.1.0", "karma-phantomjs-launcher": "~0.1.0", "karma": "~0.10.4", "karma-ng-html2js-preprocessor": "~0.1.0" }, "engines": { "node": ">=0.8.0", "npm": "1.3.x" }, "scripts": { "test": "grunt test", "postinstall": "node_modules/.bin/bower install;node_modules/.bin/grunt server:dist" } } 

在我的package.json当我键入./node_modules/.bin/grunt我得到:

 Warning: Task "jshint" not found. Use --force to continue. Aborted due to warnings. 

但是当我将grunt依赖关系移动到devDependencies

  { "name": "js-linkedin-connector", "version": "0.1.0", "dependencies": { "passport": "~0.1.17", "passport-local": "~0.1.6", "passport-linkedin-oauth2": "~1.0.1", "connect": "~2.11.0", "underscore": "~1.5.2", "bower": "1.2.x" }, "devDependencies": { "grunt": "~0.4.1", "grunt-cli": "0.1.11", "load-grunt-tasks": "~0.1.0", "grunt-contrib-copy": "~0.4.1", "grunt-contrib-concat": "~0.3.0", "grunt-contrib-coffee": "~0.7.0", "grunt-contrib-uglify": "~0.2.0", "grunt-contrib-compass": "~0.5.0", "grunt-contrib-jshint": "~0.6.0", "grunt-contrib-cssmin": "~0.6.0", "grunt-contrib-connect": "~0.5.0", "grunt-contrib-clean": "~0.5.0", "grunt-contrib-htmlmin": "~0.1.3", "grunt-contrib-watch": "~0.5.2", "grunt-autoprefixer": "~0.2.0", "grunt-usemin": "~2.0.0", "grunt-svgmin": "~0.2.0", "grunt-rev": "~0.1.0", "grunt-concurrent": "~0.3.0", "grunt-jasmine-node": "~0.1.0", "grunt-google-cdn": "~0.2.0", "grunt-ngmin": "~0.0.2", "time-grunt": "~0.1.0", "grunt-karma": "~0.6.2", "connect-livereload": "~0.3.0", "karma-ng-scenario": "~0.1.0", "karma-script-launcher": "~0.1.0", "karma-chrome-launcher": "~0.1.0", "karma-firefox-launcher": "~0.1.0", "karma-html2js-preprocessor": "~0.1.0", "karma-jasmine": "~0.1.3", "karma-requirejs": "~0.1.0", "karma-phantomjs-launcher": "~0.1.0", "karma": "~0.10.4", "karma-ng-html2js-preprocessor": "~0.1.0" }, "engines": { "node": ">=0.8.0", "npm": "1.3.x" }, "scripts": { "test": "grunt test", "postinstall": "node_modules/.bin/bower install;node_modules/.bin/grunt server:dist" } } 

一切正常。

有什么问题,我该如何解决它将我的grunt + bower应用程序部署到heroku?

将你的Grunt依赖关系保存在devDependencies中。 使用自定义的buildpack允许Heroku在他们的平台上执行你的Gruntstream。

示例应用程序,显示如何做到这一点

Buildpack允许您以不同的方式启动应用程序,在这种情况下,您需要从configuration设置中更改它:

 heroku config:set BUILDPACK_URL=https://github.com/mbuchetics/heroku-buildpack-nodejs-grunt.git 

那么只需要在你的Gruntconfiguration中添加一个heroku任务即可。

其实,我已经尝试了一些方法来确定哪些是有效的,哪些不适合我。 我需要用uglify来缩小我的脚本。

  1. 首先,我添加了grunt和grunt-contrib-uglify到我的devDependencies(就像我在我的机器上开发的那样),并尝试了package.json中的“postinstall”脚本:

     "scripts": { "start": "node index.js", "postinstall": "grunt uglify" }, "devDependencies": { "grunt": "~0.4.4", "grunt-contrib-uglify": "^0.4.0" } 

    这显然没有工作,因为heroku不安装devDependencies。

  2. 在这之后,我build立了buildpack,在我的Gruntfile.js中添加了一个heroku任务,删除了安装后的脚本并尝试推送。

    这也是不成功的,因为buildpack只安装了grunt-cli和grunt,而不是grunt-contrib-uglify。

  3. 接下来我将grunt&grunt-contrib-uglify从devDependencies移到了依赖项。 (如果我移动uglify,为什么我不应该移动grunt)。 这样,它的工作,但让我感觉:为什么我需要的buildpack,如果我不得不添加咕噜依赖?

  4. 我已经恢复到默认的buildpack

     heroku config:unset BUILDPACK_URL 

    并添加了上面提到的postinstall脚本。 这不起作用,因为grunt命令仍然丢失。

  5. 最后,我还将grunt-cli添加到依赖关系中,并且现在可以运行,而无需构build包。

结论:你不需要buildpack,并将你的grunt依赖添加到“dependencies”。 或者,buildpack应该修复这个问题: https : //github.com/mbuchetics/heroku-buildpack-nodejs-grunt/issues/5