fix legacy script tag generation

This commit is contained in:
Miao Wang 2024-04-10 02:27:09 +08:00
parent 3fb7919da8
commit 41618e6ed1
2 changed files with 7 additions and 4 deletions

View File

@ -1,5 +1,8 @@
{% capture entry %}{% if page.layout and layout.jsEntry %}{{ layout.jsEntry }}{% elsif page.jsEntry %}{{ page.jsEntry }}{% else %}default{% endif %}{% endcapture %}
{% vite_javascript_tag {{ entry }} %}
{% capture entry_legacy %}{{ entry }}-legacy.js{% endcapture %}
<script src="{% vite_asset_path /vite/legacy-polyfills-legacy %}" defer nomodule></script>
<script src="{% vite_asset_path {{ entry_legacy }} %}" defer nomodule></script>
<script nomodule>
!function(){var e=document,t=e.createElement("script");if(!("noModule"in t)&&"onbeforeload"in t){var n=!1;e.addEventListener("beforeload",(function(e){if(e.target===t)n=!0;else if(!e.target.hasAttribute("nomodule")||!n)return;e.preventDefault()}),!0),t.type="module",t.src=".",e.head.appendChild(t),t.remove()}}();
</script>
<script src="{% vite_asset_path /vite/legacy-polyfills-legacy %}" crossorigin="anonymous" id="vite-legacy-polyfill" nomodule></script>
{% capture legacyFile %}{% vite_asset_path {{ entry }}-legacy.js %}{% endcapture %}
<script nomodule defer>System.import({{ legacyFile | jsonify }});</script>

View File

@ -132,7 +132,7 @@ protected
# Internal: Renders HTML attributes inside a tag.
def stringify_attrs(**attrs)
attrs.map { |key, value| %(#{ key }="#{ value }") }.join(' ')
attrs.map { |key, value| %(#{ key }#{ value && value != "" ? %(="#{value}") : "" }) }.join(' ')
end
# Internal: Renders an HTML tag of the specified type.