在 heroku-buildpack-static 中使用变量
Using variables with heroku-buildpack-static
我有一个 monorepo,其中包含一个 React 应用程序。我正在使用 The create-react-app Buildpack, which uses 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?
所以你的主要 buildpack
是 create-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
您正在寻找的功能在 buildpack heroku-buildpack-static
中。如果我们查看相同的源代码
只有3个变量支持插值,我们可以在
看到相同的
现在我们也可以在 root
变量中进行插值,我们需要修改代码
json["root"] ||= DEFAULT[:root]
json["root"] = NginxConfigUtil.interpolate(json["root"], ENV) if json["root"]
所以我分叉了回购以更新相同的
但是由于 buildpacks 是在 create-react-app-buildpack 中定义的,所以我们需要分叉它并更新 .buildpacks
文件,如下所示
现在我们使用这个分叉的仓库作为我们的构建包
$ 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
现在构建工作正常
我有一个 monorepo,其中包含一个 React 应用程序。我正在使用 The create-react-app Buildpack, which uses 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?
所以你的主要 buildpack
是 create-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
您正在寻找的功能在 buildpack heroku-buildpack-static
中。如果我们查看相同的源代码
只有3个变量支持插值,我们可以在
看到相同的现在我们也可以在 root
变量中进行插值,我们需要修改代码
json["root"] ||= DEFAULT[:root]
json["root"] = NginxConfigUtil.interpolate(json["root"], ENV) if json["root"]
所以我分叉了回购以更新相同的
但是由于 buildpacks 是在 create-react-app-buildpack 中定义的,所以我们需要分叉它并更新 .buildpacks
文件,如下所示
现在我们使用这个分叉的仓库作为我们的构建包
$ 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
现在构建工作正常