Precompiling assets for deployment within a Rails Engine #448
demsullivan
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
There's a couple of threads on here about Rails engines, but we ran into trouble pretty quickly following the advice from #95 and the example engine code in
examples/
This post is intended to illustrate an issue we ran into with gem version mismatches, and how we solved it, in the hopes that this might help others who are using Rails Engines!
Setup
Our setup follows the example engine almost exactly:
Deployment Issues
This setup works great for development - as long as we're running a separate
bin/vite dev
within the engine's root, we get full HMR on the engine, etc.For precompiling and deployment, however, we ran into problems when the gem versions in the engine's
Gemfile.lock
differ from the host app. In this case, when we runbin/vite build
from within the engine, we get the following error:Solution
As a preliminary solution, we found that running
bin/vite
within the host app and overriding the config with environment variables allowed us to successfully compile the engine's assets.Following the above example:
VITE_RUBY_ROOT=`bundle show my_engine` VITE_RUBY_PUBLIC_OUTPUT_DIR=my-engine-vite bin/vite build
As a next step, I'm looking into automating this... possibly by hooking into the
vite:build
Rake task, iterating over all of the gems that have aconfig/vite.json
, reading the values from it, and running the above command from the host app's root.If anyone has any additional suggestions, happy to hear them! Otherwise, hope this helps someone ❤️
Beta Was this translation helpful? Give feedback.
All reactions