Skip to content

Commit

Permalink
feat: allow options to be passed to legacy helpers (#474)
Browse files Browse the repository at this point in the history
  • Loading branch information
josephnle authored Nov 6, 2024
1 parent b92ef4b commit 642c178
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions vite_plugin_legacy/lib/vite_plugin_legacy/tag_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,27 @@
module VitePluginLegacy::TagHelpers
# Public: Renders a <script> tag for the specified Vite entrypoints when using
# @vitejs/plugin-legacy, which injects polyfills.
def vite_legacy_javascript_tag(name, asset_type: :javascript)
def vite_legacy_javascript_tag(name, asset_type: :javascript, **options)
return if ViteRuby.instance.dev_server_running?

legacy_name = name.sub(/(\..+)|$/, '-legacy\1')
import_tag = content_tag(:script, nomodule: true) {
import_tag = content_tag(:script, nomodule: true, **options) {
"System.import('#{vite_asset_path(legacy_name, type: asset_type)}')".html_safe
}

safe_join [vite_legacy_polyfill_tag, import_tag]
safe_join [vite_legacy_polyfill_tag(**options), import_tag]
end

# Public: Same as `vite_legacy_javascript_tag`, but for TypeScript entries.
def vite_legacy_typescript_tag(name)
vite_legacy_javascript_tag(name, asset_type: :typescript)
def vite_legacy_typescript_tag(name, **options)
vite_legacy_javascript_tag(name, asset_type: :typescript, **options)
end

# Internal: Renders the vite-legacy-polyfill to enable code splitting in
# browsers that do not support modules.
def vite_legacy_polyfill_tag
def vite_legacy_polyfill_tag(**options)
return if ViteRuby.instance.dev_server_running?

content_tag(:script, nil, nomodule: true, src: vite_asset_path("legacy-polyfills", type: :virtual))
content_tag(:script, nil, nomodule: true, src: vite_asset_path("legacy-polyfills", type: :virtual), **options)
end
end

0 comments on commit 642c178

Please sign in to comment.