vite_ruby
vite_ruby copied to clipboard
After upgrading to Vite 4.2.0, running build multiple times resulted in 2 different hashes, for the same files
Description 📖
I originally posted an issue on the vite repo (https://github.com/vitejs/vite/issues/13071) but upon further investigation I think it might be more relevant here.
We recently tried deploying our Rails7 + Vue 3 + Vite 4.2.0 (from Vite 2.9) update and since we have multiple app servers we noticed that when Capistrano ran precompile it generated two different hashes on different servers (and only two).
I reproduced this locally so it's not just an issue with our servers.
The difference between the files:
../../public/vite/assets/application-8f133cfb.js
nne = function (e) {
return "/vite/" + e;
},
../../public/vite/assets/application-06ecfed2.js
nne = function (e) {
return "https://xyz.cloudfront.net/vite/" + e;
},
It seems the first one 8f133cfb
happened after the first build but re-running bundle exec vite build --force
multiple times continually produced 06ecfed2
(with the proper CDN path).
Any ideas on why it might not be inserting the CDN the first time around?
We're attempting to try Vite 4.3.4 at the moment to see if it helps...
System info
package.json:
"@vitejs/plugin-vue": "4.1.0",
"@vitejs/plugin-vue-jsx": "3.0.0",
"vite": "2.9.13",
"vite-plugin-ruby": "3.0.12",
"vue": "3.2.47",
Gemfile.lock
vite_rails (3.0.14)
railties (>= 5.1, < 8)
vite_ruby (~> 3.0, >= 3.2.2)
vite_ruby (3.3.0)
dry-cli (>= 0.7, < 2)
rack-proxy (~> 0.6, >= 0.6.1)
zeitwerk (~> 2.2)
Hi Daniel!
Based on the example you provided, and assuming you are configuring asset_host
in Rails, you might want to check the build output to verify that it's not printing this error the first time.
To discard whether this is the problem, I'd suggest explicitly configuring VITE_RUBY_ASSET_HOST
, and see whether that prevents the problem.
Vite Rails will attempt to load the Rails app before building, in order to access the action_controller.asset_host
as configured in the current environment (RAILS_ENV
).