今天我想将我的node.js
应用程序部署到heroku.本地我也在使用bower
和grunt
开发,我还想继续使用它们.
现在,按照我在网上找到的一些建议,我加入bower
了我的dependencies
并添加"postinstall": "node_modules/.bin/bower install
到我的网站package.json
postinstall
.
现在我遇到了一些问题grunt
.当我将我的呼噜声依赖于dependencies
从devDependencies
grunt
不认我的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在其平台上执行Grunt流.
示例应用程序,显示如何做到这一点
Buildpacks允许您以不同方式启动应用程序,在这种情况下,您将要从配置设置更改它:
heroku config:set BUILDPACK_URL=https://github.com/mbuchetics/heroku-buildpack-nodejs-grunt.git
然后,只需heroku
在Grunt配置中添加任务即可.
实际上,我已经尝试了一些方法来确定哪些方法有效,哪些方法无效.我需要用uglify缩小我的脚本.
首先,我将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.
在此之后,我设置了buildpack,在我的Gruntfile.js中添加了一个heroku任务,删除了postinstall脚本并尝试推送.
这也是不成功的,因为buildpack只安装了grunt-cli和grunt,但没有安装grunt-contrib-uglify.
接下来,我将grunt&grunt-contrib-uglify移至devDependencies的依赖项.(如果我移动uglify,为什么我不能移动咕噜声).这种方式有用,但让我觉得:为什么我需要buildpack,如果我必须添加grunt依赖项?
我已经恢复到默认的buildpack
heroku config:unset BUILDPACK_URL
并添加了上面提到的postinstall脚本.这不起作用,因为grunt命令仍然缺失.
最后,我还将grunt-cli添加到依赖项中,现在它可以运行,没有buildpack!
结论:您不需要buildpack - 并将您的grunt依赖项添加到"依赖项".或者,buildpack应该解决这个问题:https://github.com/mbuchetics/heroku-buildpack-nodejs-grunt/issues/5