mirror-web/_includes/vite_script.html
2025-04-10 22:42:55 +08:00

67 lines
2.5 KiB
HTML

{% capture entry %}{% if page.layout and layout.jsEntry %}{{ layout.jsEntry }}{% elsif page.jsEntry %}{{ page.jsEntry }}{% else %}default{% endif %}{% endcapture %}
{% vite_typescript_tag {{ entry }} %}
<script nomodule>
/*
Workaround for Safari 10.1, which does not support the `nomodule` attribute.
*/
(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.ts %}{% endcapture %}
<script nomodule defer>System.import({{ legacyFile | jsonify }});</script>
<!--
load moduleGuard.ts as a module, to detect whether the browser can correctly
load the module.
Sometimes if we are behind a proxy, the scripts may be wrapped in a function
and the module may not be loaded correctly.
In that case, we will load the legacy build.
-->
<script src="{% vite_asset_path moduleGuard.ts %}" crossorigin="anonymous" type="module"></script>
<!--
jekyll-minifier only minify scripts with type="application/javascript",
here data-dummytype is added to trick jekyll-minifier to minify the script.
-->
<script data-dummytype="application/javascript" type="module">
(function(){
var loadLegacy = function() {
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);
}
try{
new Function("m","return import(m)");
document.addEventListener("DOMContentLoaded", function(){
if(!document.documentElement.hasAttribute("data-module-loaded")){
console.warn("vite: loading legacy build because esm module is not loaded");
loadLegacy();
}
});
}catch(e){
console.warn("vite: loading legacy build because dynamic import is unsupported, syntax error above should be ignored");
loadLegacy();
}
})();
</script>