mirror-web/_includes/vite_script.html

43 lines
1.6 KiB
HTML

{% capture entry %}{% if page.layout and layout.jsEntry %}{{ layout.jsEntry }}{% elsif page.jsEntry %}{{ page.jsEntry }}{% else %}default{% endif %}{% endcapture %}
{% vite_javascript_tag {{ entry }} %}
<script nomodule>
(function() {
var check = document.createElement('script');
if (!('noModule' in check) && 'onbeforeload' in check) {
var support = false;
document.addEventListener('beforeload', function(e) {
if (e.target === check) {
support = true;
} else if (!e.target.hasAttribute('nomodule') || !support) {
return;
}
e.preventDefault();
}, true);
check.type = 'module';
check.src = '.';
document.head.appendChild(check);
check.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>
<script type="module">
(function(){
try{
new Function("m","return import(m)");
}catch(e){
console.warn("vite: loading legacy build because dynamic import is unsupported, syntax error above should be ignored");
var polyScript = document.getElementById("vite-legacy-polyfill");
var newScript = document.createElement("script");
newScript.src = polyScript.src;
newScript.onload = function(){
System.import({{ legacyFile | jsonify }});
};
document.body.appendChild(newScript);
}
})();
</script>