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

feat: allow options to be passed to legacy helpers #474

Merged
merged 2 commits into from
Nov 6, 2024
Merged
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
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