【问题标题】:How to run `npm install && bower install` before `sbt compile` for Heroku Deployment?如何在 Heroku 部署的`sbt compile` 之前运行`npm install && bower install`?
【发布时间】:2017-09-26 09:49:19
【问题描述】:

我正在开发一个 Playframework 项目,该项目在子目录 ./ui 中有前端代码,并由 Grunt 使用 https://github.com/tuplejump/play-yeoman 管理

目前我使用https://github.com/heroku/heroku-buildpack-multi并设置

https://github.com/heroku/heroku-buildpack-nodejs.git
https://github.com/heroku/heroku-buildpack-scala.git

在 .buildpacks 文件中。

并设置

{
  "name": "scala-grunt",
  "dependencies": {
    "grunt-cli": "0.1.13"
  },
  "devDependencies": {
    "grunt": "~0.4.5"
  },
  "version": "0.1.0",
  "engines": {
    "node": "~0.10.21"
  }

}

在根目录的package.json文件中。

但是,当我将代码库推送到 heroku 时,它会抛出异常 Fatal error: Unable to find local grunt. 我认为这是因为 sbt 不会在 ./ui 目录中运行 npm install && bower install

有没有人知道如何在 heroku 中在 sbt compile 之前运行命令 npm install && bower install

【问题讨论】:

  • 你知道sbt-heroku插件吗?使用此插件,您可以在本地部署您的 play 应用程序并将其部署到 Heroku。剩下的就是用必要的东西来暂存应用程序。

标签: node.js scala heroku


【解决方案1】:

查看https://docs.npmjs.com/misc/scripts。您可以使用几个关键字在不同时间运行 bower 和 grunt。查看preinstallpostinstall 关键字。

例如,这是我经常使用的 package.json 文件中的脚本部分。

"scripts": {
    "start": "node lib/app.js",
    "postinstall": "bower install --allow-root",
    "test": "grunt"
}

【讨论】:

    【解决方案2】:

    这个命令为我解决了:

    heroku buildpacks:set https://github.com/heroku/heroku-buildpack-multi.git
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-09-14
      • 2015-12-15
      • 2014-12-14
      • 1970-01-01
      • 2020-11-26
      • 1970-01-01
      • 2017-02-12
      相关资源
      最近更新 更多