diff --git a/vite_rails/lib/vite_rails/tag_helpers.rb b/vite_rails/lib/vite_rails/tag_helpers.rb index 434282cf..5db459e2 100644 --- a/vite_rails/lib/vite_rails/tag_helpers.rb +++ b/vite_rails/lib/vite_rails/tag_helpers.rb @@ -45,7 +45,11 @@ def vite_typescript_tag(*names, **options) # Public: Renders a tag for the specified Vite entrypoints. def vite_stylesheet_tag(*names, **options) - style_paths = names.map { |name| vite_asset_path(name, type: :stylesheet) } + force_build = options.delete(:force_build) + style_paths = names.map { |name| vite_asset_path(name, type: :stylesheet, force_build: force_build) } + if force_build + style_paths.map! { |path| path + "?force_build=true" } + end stylesheet_link_tag(*style_paths, **options) end diff --git a/vite_ruby/lib/vite_ruby/dev_server_proxy.rb b/vite_ruby/lib/vite_ruby/dev_server_proxy.rb index b9a1f079..14649752 100644 --- a/vite_ruby/lib/vite_ruby/dev_server_proxy.rb +++ b/vite_ruby/lib/vite_ruby/dev_server_proxy.rb @@ -50,6 +50,8 @@ def forward_to_vite_dev_server(env) def vite_should_handle?(env) path, query, referer = env['PATH_INFO'], env['QUERY_STRING'], env['HTTP_REFERER'] + return false if query&.include?('force_build=true') + return true if path.start_with?(vite_asset_url_prefix) # Vite asset return true if path.start_with?(VITE_DEPENDENCY_PREFIX) # Packages and imports return true if query&.start_with?('t=') # Hot Reload for a stylesheet diff --git a/vite_ruby/lib/vite_ruby/manifest.rb b/vite_ruby/lib/vite_ruby/manifest.rb index 5ffaed0f..e39671bb 100644 --- a/vite_ruby/lib/vite_ruby/manifest.rb +++ b/vite_ruby/lib/vite_ruby/manifest.rb @@ -77,10 +77,10 @@ def lookup!(*args, **options) # Example: # manifest.lookup('calendar.js') # => { "file" => "/vite/assets/calendar-1016838bab065ae1e122.js", "imports" => [] } - def lookup(name, type: nil) - @build_mutex.synchronize { builder.build } if should_build? + def lookup(name, type: nil, force_build: false) + @build_mutex.synchronize { builder.build } if force_build || should_build? - find_manifest_entry(with_file_extension(name, type)) + find_manifest_entry(with_file_extension(name, type), force_build: force_build) end private @@ -96,8 +96,8 @@ def should_build? end # Internal: Finds the specified entry in the manifest. - def find_manifest_entry(name) - if dev_server_running? + def find_manifest_entry(name, force_build: false) + if dev_server_running? && !force_build { 'file' => prefix_vite_asset(name.to_s) } else manifest[name.to_s]