heroku - 在 heroku-buildpack-static 中使用变量

标签 heroku monorepo

我有一个 monorepo,其中包含一个 React 应用程序。我正在使用 create-react-app Buildpack ,它使用 heroku-buildpack-static提供东西。

由于该应用位于 foo/examples/bar 中,因此我创建了以下 static.json:

{
  "root": "foo/examples/${EXAMPLE}/build/",
  "routes": {
    "/**": "index.html"
  }
}

还有一个EXAMPLE 配置变量,其值为bar。根据docs ,这应该有效。

当应用程序由 heroku 构建时,我在日志中看到了这一点:

app[web.1]: nginx: [emerg] unknown "example" variable
app[web.1]: Process exited unexpectedly: nginx
app[web.1]: Going down, terminating child processes...
heroku[web.1]: State changed from starting to crashed
heroku[web.1]: Process exited with status 1

有没有办法修复这个构建,或者有更好的方法来部署这种 repo?

最佳答案

所以你的主要buildpackcreate-react-app-buildpack .

然后使用 3 个 buildpacks,如 create-react-app-buildpack 所示

https://github.com/heroku/heroku-buildpack-nodejs.git
https://github.com/mars/create-react-app-inner-buildpack.git#v9.0.0
https://github.com/heroku/heroku-buildpack-static.git

您正在寻找的功能在构建包 heroku-buildpack-static 中。如果我们查看相同的源代码

只有3个变量支持插值,我们可以看到相同的

heroku-buildpack-static

现在我们也要在 root 变量中进行插值,我们需要像这样修改代码

json["root"] ||= DEFAULT[:root]
json["root"] = NginxConfigUtil.interpolate(json["root"], ENV) if json["root"]

所以我 fork 了 repo 以更新相同的内容

heroku-buildpack-static

但是由于构建包是在 create-react-app-buildpack 中定义的,所以我们需要 fork 并更新 .buildpacks 文件,如下所示

create-react-app-buildpack

现在我们使用这个 fork 的仓库作为我们的构建包

$ heroku config:set  JS_RUNTIME_TARGET_BUNDLE="/app/packages/examples/grid/build/static/js/*.js"
$ heroku buildpacks:set https://github.com/tarunlalwani/heroku-buildpack-static.git
$ heroku config:set  EXAMPLE=grid
$ heroku push origin master

现在构建工作正常

Working fine

关于heroku - 在 heroku-buildpack-static 中使用变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57255126/

相关文章:

ruby - 你如何在 Heroku 中安装 filemagic (libmagic)?

java - 使用 MongoDB 实现用于 hibernate 搜索的目录提供程序

ruby-on-rails - 如何修复由 coffeescript/asset 管道产生的这个奇怪的 LoadError 错误?

node.js - Monorepo – Yarn workspaces Typescript Node.JS 项目 – 运行 nodemon 时找不到模块

TypeScript:同时观察和编译多个目录(monorepo)

python - 使用 Redis 添加重复任务

ruby-on-rails - 在推送到 Heroku 之前删除 Rails 中的预编译 Assets

javascript - Building Typescript : [! ] Error: Unexpected token (注意你需要插件来导入不是 JavaScript 的文件)

angular - 如何从 mono 存储库构建 NestJs api

git - 带有 git bash 的 monorepo 中的 ci/cd 独立微服务