Compiling translations while deploying to Heroku #710
Replies: 2 comments 1 reply
-
you can write a custom task that combines the generation of i18n-js translations and any other operations you perform during assets:precompile. Create a file named lib/tasks/custom_i18n_js.rake:
then add the file to gitignore and execute heroku build, |
Beta Was this translation helpful? Give feedback.
-
We recently upgraded an app to v4 and ran into problems trying to deploy to Heroku as well. And while the above rake tasks provided excellent pointers, we needed a bit more trickery to make things work, so I figured I might as well leave the tale here. First, a little bit about our setup:
When we tried to deploy we got the following error during Herokus build phase:
which indicates the translations.json file isn't getting exported, even though we had a rake task like the above: namespace :i18n do
namespace :js do
desc "Exports translations to be used by i18n-js"
task :export => :environment do
`bundle exec i18n export`
end
end
end
# Run `i18n export` prior to building Javascript assets, so translations are
# available for use. javascript:build is the rake task run by jsbundling
# during assets:precompile
Rake::Task["javascript:build"].enhance(["i18n:js:export"]) Turns out we were running the nodejs buildpack first (since that's the recommended order in order to control Node and Yarn versions). The nodejs buildpack by default runs your "scripts": {
"build": "webpack --config webpack.config.js"
} Unfortunately, this meant that the nodejs buildpack would try to compile our assets before the above rake task was even invoked and even before our Ruby dependencies had been installed. There's no chance for our translations to have been exported at this point. Luckily Heroku provides a way to customize the build process, which we can use to tell Heroku to not build anything during the build step of the nodejs buildpack: "scripts": {
"build": "webpack --config webpack.config.js",
"heroku-postbuild": ""
} With this in place in
Here's hoping this saves someone else the headaches I had figuring it out. |
Beta Was this translation helpful? Give feedback.
-
Hello!
Thank you for a great gem, we are working on migrating from v3 to v4 and the workflow works great for development.
Right now we are committing the file with translations to git, but if we could get it to work on deploy we could gitignore the file and consider it an asset instead.
Do anyone have a nice way for configuring it on Heroku Deploy?
We already have some hooks into the
assets:precompile
to cleanup unused assets, but since there is no longer a rake-task that is not as straight forward.Beta Was this translation helpful? Give feedback.
All reactions