Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force skipping vite dev server #93

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion vite_rails/lib/vite_rails/tag_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ def vite_typescript_tag(*names, **options)

# Public: Renders a <link> 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

Expand Down
2 changes: 2 additions & 0 deletions vite_ruby/lib/vite_ruby/dev_server_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions vite_ruby/lib/vite_ruby/manifest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is wrong, we don't want to force build in production for example.

The correct way should be something like config.auto_build && (!dev_server_running? || force_build)


find_manifest_entry(with_file_extension(name, type))
find_manifest_entry(with_file_extension(name, type), force_build: force_build)
end

private
Expand All @@ -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]
Expand Down