簡體   English   中英

在 heroku-buildpack-static 中使用變量

[英]Using variables with heroku-buildpack-static

我有一個 monorepo,其中包含一個 React 應用程序。 我正在使用create-react-app Buildpack ,它使用heroku-buildpack-static來提供服務。

由於應用程序在foo/examples/bar ,我創建了以下static.json

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

以及一個值為barEXAMPLE配置變量。 根據文檔,這應該有效。

當應用程序由 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 個buildpackscreate-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

您正在尋找的功能在 buildpack heroku-buildpack-static 如果我們看同樣的源代碼

只有 3 個變量支持插值,我們可以在

heroku-buildpack-static

現在為了讓我們也獲得root變量的插值,我們需要修改代碼,如

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

所以我分叉了 repo 來更新相同的

heroku-buildpack-static

但是由於 buildpacks 是在create-react-app- buildpack 中定義的,所以我們需要 fork 並更新.buildpacks文件,如下所示

create-react-app-buildpack

現在之后我們使用這個分叉倉庫作為我們的構建包

$ 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

現在構建工作正常

工作正常

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM