How can I invoke npm on heroku command line (to install bower components)?

我的梦境 提交于 2019-11-27 10:30:46

问题


Bower is for client side Javascript what npm is for the server side and reads a component.json file to recognize dependencies that should be fetched at deploy time so I'd be happy it heroku would run it at slug compilation time.

Unfortunately I can not invoke npm or bower from a heroku console or one-off command (heroku run "npm help") (heroku run bash -> npm help) as it's possible with ruby's rake. I've put npm and node (latest/x versions) in my package.json but in the engines section, not the dependencies.

I think this could be solved by customizing the node buildpack but I consider this a little too heavy task just for activating something so obvious.


回答1:


You can also setup a postintall command, something like this in your package.json

"dependencies": {
    "bower": "0.6.x"
},
"scripts": {
    "postinstall": "./node_modules/bower/bin/bower install"
}

Then npm install will also install bower dependencies.

Pros : one command to rule them all.

Cons : you unnecessarily embed bower as a dependency.




回答2:


You can use run like this:

heroku run npm install git://github.com/webjay/kaiseki



回答3:


You should declare NPM dependencies in the package.json file

All you install from shell will be deleted on exit shell. You are in a cloned instance.




回答4:


You can use bower directly like this

"dependencies": {
    "bower": "^1.7.9"
},
"scripts": {
    "postinstall": "sudo bower install --allow-root "
}


来源:https://stackoverflow.com/questions/14736941/how-can-i-invoke-npm-on-heroku-command-line-to-install-bower-components

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!