Module: VitePluginLegacy::TagHelpers

Defined in:
lib/vite_plugin_legacy/tag_helpers.rb

Overview

Public: Allows to render HTML tags for scripts and styles processed by Vite.

Instance Method Summary collapse

Instance Method Details

#vite_legacy_javascript_tag(name, asset_type: :javascript) ⇒ Object

Public: Renders a <script> tag for the specified Vite entrypoints when using @vitejs/plugin-legacy, which injects polyfills.



7
8
9
10
11
12
13
14
15
16
# File 'lib/vite_plugin_legacy/tag_helpers.rb', line 7

def vite_legacy_javascript_tag(name, asset_type: :javascript)
  return if ViteRuby.instance.dev_server_running?

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

  safe_join [vite_legacy_polyfill_tag, import_tag]
end

#vite_legacy_polyfill_tagObject

Internal: Renders the vite-legacy-polyfill to enable code splitting in browsers that do not support modules.



25
26
27
28
29
# File 'lib/vite_plugin_legacy/tag_helpers.rb', line 25

def vite_legacy_polyfill_tag
  return if ViteRuby.instance.dev_server_running?

  (:script, nil, nomodule: true, src: vite_asset_path('legacy-polyfills', type: :virtual))
end

#vite_legacy_typescript_tag(name) ⇒ Object

Public: Same as ‘vite_legacy_javascript_tag`, but for TypeScript entries.



19
20
21
# File 'lib/vite_plugin_legacy/tag_helpers.rb', line 19

def vite_legacy_typescript_tag(name)
  vite_legacy_javascript_tag(name, asset_type: :typescript)
end