-
-
Notifications
You must be signed in to change notification settings - Fork 12
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
@zhoujinfu Is it convenient to file an issue to discuss your problem? #6
Comments
When i remove the dynamic base in |
it seems that the plugin does not work well with |
I am very happy to receive your feedback, I will investigate it in the near future, and I will reply to you as soon as there is progress. |
The problem I have roughly located is that the resources of pwa will not use publicPath, so the matching method of base+publicPath will not take effect on it. I need to implement my previous base tag plan in advance. |
@zhoujinfu You can try version 0.4.0 |
I tried v0.4.0. see my forked HEAD on branch main zhoujinfu@d9e6cb1. I tested the examples update The output <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" >
<link rel="icon" href="/__dynamic_base__/favicon.ico" >
<meta name="viewport" content="width=device-width, initial-scale=1.0" >
<title>Vite App</title>
<script>
window.__dynamic_base__ = 'http://localhost:8090/base'
</script>
<link rel="manifest" href="/__dynamic_base__/manifest.webmanifest"><script src="/__dynamic_base__/registerSW.js"></script> <script>
(function(){
var preloads = [{"parentTagName":"head","tagName":"script","attrs":{"type":"module","crossorigin":"","src":"/__dynamic_base__/assets/index.471d4ef9.js"}},{"parentTagName":"head","tagName":"link","attrs":{"rel":"stylesheet","href":"/__dynamic_base__/assets/index.a2f9fb2a.css"}}];
function assign() {
var target = arguments[0];
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
return target;
};
for(var i = 0; i < preloads.length; i++){
var item = preloads[i]
var childNode = document.createElement(item.tagName);
assign(childNode, item.attrs)
if(window.__dynamic_base__) {
if(item.tagName == 'link') {
assign(childNode, { href: window.__dynamic_base__ + item.attrs.href })
} else if (item.tagName == 'script') {
assign(childNode, { src: window.__dynamic_base__ + item.attrs.src })
}
}
document.getElementsByTagName(item.parentTagName)[0].appendChild(childNode);
}
})();
</script>
<script type="module">try{import("_").catch(()=>1);}catch(e){}window.__vite_is_dynamic_import_support=true;</script>
<script type="module">!function(){if(window.__vite_is_dynamic_import_support)return;console.warn("vite: loading legacy build because dynamic import is unsupported, syntax error above should be ignored");var e=document.getElementById("vite-legacy-polyfill"),n=document.createElement("script");n.src=window.__dynamic_base__+e.src,n.onload=function(){System.import(window.__dynamic_base__+document.getElementById('vite-legacy-entry').getAttribute('data-src'))},document.body.appendChild(n)}();</script>
</head>
<body>
<div id="app"></div>
<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 nomodule id="vite-legacy-polyfill" src="/__dynamic_base__/assets/polyfills-legacy.c9aac887.js"></script>
<script nomodule id="vite-legacy-entry" data-src="/__dynamic_base__/assets/index-legacy.7573112a.js">System.import(window.__dynamic_base__+document.getElementById('vite-legacy-entry').getAttribute('data-src'))</script>
</body>
</html>
base: process.env.NODE_ENV === "production" ? "/__dynamic_base__/" : "/",
it cause the pwa cache failed. when i try to |
Maybe we should make dynamic_base work with pwa |
/**
* The precacheAndRoute() method efficiently caches and responds to
* requests for URLs in the manifest.
* See https://goo.gl/S9QRab
*/
workbox.precacheAndRoute([{
"url": "assets/About-legacy.dbc6d110.js",
"revision": null
}, {
"url": "assets/About.33979b2a.css",
"revision": null
}, {
"url": "assets/About.e66d53d5.js",
"revision": null
}, {
"url": "assets/en-legacy.619c3de7.js",
"revision": null
}, {
"url": "assets/en.44253359.js",
"revision": null
}, {
"url": "assets/Home-legacy.99ddbe6a.js",
"revision": null
}, {
"url": "assets/Home.4c818565.js",
"revision": null
}, {
"url": "assets/index-legacy.7573112a.js",
"revision": null
}, {
"url": "assets/index.1225a17d.css",
"revision": null
}, {
"url": "assets/index.471d4ef9.js",
"revision": null
}, {
"url": "assets/polyfills-legacy.c9aac887.js",
"revision": null
}, {
"url": "assets/zh-cn-legacy.b2112d92.js",
"revision": null
}, {
"url": "assets/zh-cn.08710dfd.js",
"revision": null
}, {
"url": "index.html",
"revision": "276616a31a95eafa39fefd12afcda1cc"
}, {
"url": "registerSW.js",
"revision": "042db6f1e2458b14f0394bfb9de65a5c"
}, {
"url": "manifest.webmanifest",
"revision": "8c4f6e7053426ecf6e30816264128994"
}], {});
workbox.cleanupOutdatedCaches();
workbox.registerRoute(new workbox.NavigationRoute(workbox.createHandlerBoundToURL("index.html"))); In production, All the resources will uploaded to |
I have got a workaround way to work with this two plugins: zhoujinfu@89d4a90 after
if('serviceWorker' in navigator) {window.addEventListener('load', () => {navigator.serviceWorker.register('/sw.js', { scope: '/' })})}
{"name":"demo","short_name":"demo","start_url":"http://localhost:4173/","display":"standalone","background_color":"#ffffff","lang":"en","scope":"http://localhost:4173/"}
workbox.precacheAndRoute([{
"url": "http://localhost:8080/assets/About-legacy.6d7b2345.js",
"revision": null
}, {
"url": "http://localhost:8080/assets/About.1b3423d6.css",
"revision": null
}, {
"url": "http://localhost:8080/assets/About.a6f3e50f.js",
"revision": null
}, {
"url": "http://localhost:8080/assets/en-legacy.619c3de7.js",
"revision": null
}, {
"url": "http://localhost:8080/assets/en.44253359.js",
"revision": null
}, {
"url": "http://localhost:8080/assets/Home-legacy.bc056725.js",
"revision": null
}, {
"url": "http://localhost:8080/assets/Home.25d9b1cc.js",
"revision": null
}, {
"url": "http://localhost:8080/assets/index-legacy.2a26e38c.js",
"revision": null
}, {
"url": "http://localhost:8080/assets/index.9f25452d.css",
"revision": null
}, {
"url": "http://localhost:8080/assets/index.def31ac5.js",
"revision": null
}, {
"url": "http://localhost:8080/assets/polyfills-legacy.c9aac887.js",
"revision": null
}, {
"url": "http://localhost:8080/assets/zh-cn-legacy.b2112d92.js",
"revision": null
}, {
"url": "http://localhost:8080/assets/zh-cn.08710dfd.js",
"revision": null
}, {
"url": "http://localhost:4173/index.html",
"revision": "7a2c4fe6ed13f88467f25a3a8d84ed54"
}, {
"url": "http://localhost:8080/registerSW.js",
"revision": "5118d2ce258f837e94157f51c5e6f67c"
}, {
"url": "http://localhost:8080/manifest.webmanifest",
"revision": "85ea9835061b0b220d6dd437d7a56be3"
}], {});
workbox.cleanupOutdatedCaches();
workbox.registerRoute(new workbox.NavigationRoute(workbox.createHandlerBoundToURL("http://localhost:4173/index.html")));
And then the dynamic_base work well with pwa both with/without preload. Hope this may help for u. |
What if |
No, i think it will not work, because the |
I probably know what the goal is, when I'm currently having problems hacking into |
Maybe I have a solution, but I still need to try it. |
@zhoujinfu Is it convenient to file an issue to discuss your problem?
Originally posted by @chenxch in #5 (comment)
I add a minimal reproduction at my fork
The text was updated successfully, but these errors were encountered: