[英]Using variables with heroku-buildpack-static
I have a monorepo containing, among other things, a React app.我有一个 monorepo,其中包含一个 React 应用程序。 I'm using The create-react-app Buildpack , which uses heroku-buildpack-static to serve stuff.我正在使用create-react-app Buildpack ,它使用heroku-buildpack-static来提供服务。
Since the app is in foo/examples/bar
, I've created the following static.json
:由于应用程序在foo/examples/bar
,我创建了以下static.json
:
{
"root": "foo/examples/${EXAMPLE}/build/",
"routes": {
"/**": "index.html"
}
}
And an EXAMPLE
config var with the value bar
.以及一个值为bar
的EXAMPLE
配置变量。 According to the docs , this should work.根据文档,这应该有效。
When the app is built by heroku, I see this in the log:当应用程序由 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
Is there a way to fix this build, or a better way to deploy this kind of repo?有没有办法修复这个构建,或者有更好的方法来部署这种 repo?
So your main buildpack
is create-react-app-buildpack .所以你的主要buildpack
是create-react-app-buildpack 。
Which then uses 3 buildpacks
as seen at 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
The feature you are looking for is in the buildpack heroku-buildpack-static
.您正在寻找的功能在 buildpack heroku-buildpack-static
。 If we look at the source code of the same如果我们看同样的源代码
There are only 3 variables which support interpolation, we can see the same at只有 3 个变量支持插值,我们可以在
heroku-buildpack-static heroku-buildpack-static
Now for us to get interpolation in root
variable as well, we need to modify the code like现在为了让我们也获得root
变量的插值,我们需要修改代码,如
json["root"] ||= DEFAULT[:root]
json["root"] = NginxConfigUtil.interpolate(json["root"], ENV) if json["root"]
So I forked the repo to update the same所以我分叉了 repo 来更新相同的
heroku-buildpack-static heroku-buildpack-static
But since the buildpacks are defined in create-react-app-buildpack , so we need to fork that and update the .buildpacks
file as done below但是由于 buildpacks 是在create-react-app- buildpack 中定义的,所以我们需要 fork 并更新.buildpacks
文件,如下所示
create-react-app-buildpack create-react-app-buildpack
Now after that we use this forked repo as our build pack现在之后我们使用这个分叉仓库作为我们的构建包
$ 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
And now the build works fine现在构建工作正常
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.