node.js 如何在 heroku 命令行上调用 npm(安装凉亭组件)?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14736941/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 17:06:24  来源:igfitidea点击:

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

node.jsherokubower

提问by Stefan

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

Bower用于客户端 Javascript 就像 npm 用于服务器端并读取component.json文件以识别应在部署时获取的依赖项,因此我很高兴 heroku 会在 slug 编译时运行它。

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.jsonbut in the engines section, not the dependencies.

不幸的是,我无法从 Heroku 控制台或一次性命令 ( heroku run "npm help") ( heroku run bash-> npm help)调用 npm 或 bower,因为使用 ruby​​ 的 rake 是可能的。我已经把 npm 和 node(最新/x 版本)放在我的package.json但在引擎部分,而不是依赖项。

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

我认为这可以通过自定义节点 buildpack来解决,但我认为这对于激活如此明显的东西来说有点太繁重了。

回答by xavier.seignard

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

你也可以设置一个postintall命令,像这样在你的package.json

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

Then npm installwill also install bower dependencies.

然后npm install还将安装 bower 依赖项。

Pros: one command to rule them all.

优点:一个命令来统治他们。

Cons: you unnecessarily embed bower as a dependency.

缺点:您不必要地将 bower 作为依赖项嵌入。

回答by webjay

You can use runlike this:

你可以这样使用run

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

回答by dani herrera

You should declare NPM dependencies in the package.json file

您应该在 package.json 文件中声明 NPM 依赖项

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

您从 shell 安装的所有内容都将在退出 shell 时被删除。您处于克隆实例中。

回答by eGhoul

You can use bower directly like this

你可以像这样直接使用 bower

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