weifuwu 0.19.6 → 0.19.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +14 -7
- package/dist/stream.d.ts +1 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -5212,16 +5212,18 @@ function getPublicEnv() {
|
|
|
5212
5212
|
return _publicEnv;
|
|
5213
5213
|
}
|
|
5214
5214
|
function buildHeadPayload(opts) {
|
|
5215
|
-
const { ctx,
|
|
5215
|
+
const { ctx, compiledTailwindCss, isDev: isDev2 } = opts;
|
|
5216
|
+
const rb = opts.rootBase || "";
|
|
5216
5217
|
let result = "";
|
|
5217
5218
|
if (isDev2) {
|
|
5219
|
+
const vUrl = `${rb}/__wfw/v/bundle`;
|
|
5218
5220
|
result += `<script type="importmap">{
|
|
5219
5221
|
"imports": {
|
|
5220
|
-
"react": "
|
|
5221
|
-
"react-dom": "
|
|
5222
|
-
"react-dom/client": "
|
|
5223
|
-
"react/jsx-runtime": "
|
|
5224
|
-
"weifuwu/react": "
|
|
5222
|
+
"react": "${vUrl}",
|
|
5223
|
+
"react-dom": "${vUrl}",
|
|
5224
|
+
"react-dom/client": "${vUrl}",
|
|
5225
|
+
"react/jsx-runtime": "${vUrl}",
|
|
5226
|
+
"weifuwu/react": "${vUrl}"
|
|
5225
5227
|
}
|
|
5226
5228
|
}</script>
|
|
5227
5229
|
`;
|
|
@@ -5313,9 +5315,12 @@ function streamResponse(reactStream, opts) {
|
|
|
5313
5315
|
const body = buildBodyScripts(opts);
|
|
5314
5316
|
if (body) controller.enqueue(encoder2.encode("\n" + body));
|
|
5315
5317
|
if (opts.isDev) {
|
|
5318
|
+
const rb = opts.rootBase || "";
|
|
5319
|
+
const wsUrl = `${rb}/__weifuwu/livereload`;
|
|
5320
|
+
const hbUrl = `${rb}/__wfw/h/`;
|
|
5316
5321
|
controller.enqueue(encoder2.encode(
|
|
5317
5322
|
`
|
|
5318
|
-
<script>(function(){var ws=new WebSocket((location.protocol==='https:'?'wss:':'ws:')+'//'+location.host+'
|
|
5323
|
+
<script>(function(){var ws=new WebSocket((location.protocol==='https:'?'wss:':'ws:')+'//'+location.host+'${wsUrl}');var t=0;ws.onmessage=function(e){try{var m=JSON.parse(e.data);if(m.type==='component'){if(m.entry&&m.entry!==window.__WFW_ENTRY)return;import('${hbUrl}'+m.hash+'?'+Date.now()).catch(function(){location.reload()});if(m.css){var s=document.querySelector('style[data-lr]')||function(){var x=document.createElement('style');x.setAttribute('data-lr','');document.head.appendChild(x);return x}();s.textContent=m.css}return}if(m.type==='css'){var s=document.querySelector('style[data-lr]')||function(){var x=document.createElement('style');x.setAttribute('data-lr','');document.head.appendChild(x);return x}();s.textContent=m.css;return}}catch(_){}if(e.data==='reload'&&Date.now()-t>1e3){t=Date.now();location.reload()}};ws.onclose=function(){if(Date.now()-t>1e3){t=Date.now();setTimeout(function(){location.reload()},500)}}})()</script>`
|
|
5319
5324
|
));
|
|
5320
5325
|
}
|
|
5321
5326
|
} catch {
|
|
@@ -5481,6 +5486,7 @@ function ssr(path2) {
|
|
|
5481
5486
|
return streamResponse(stream, {
|
|
5482
5487
|
ctx,
|
|
5483
5488
|
base,
|
|
5489
|
+
rootBase: ctx.rootLayoutBase || "",
|
|
5484
5490
|
isDev,
|
|
5485
5491
|
bundle,
|
|
5486
5492
|
loaderData,
|
|
@@ -5675,6 +5681,7 @@ function rootLayout(dir) {
|
|
|
5675
5681
|
r.use(async (req, ctx, next) => {
|
|
5676
5682
|
const mod = await compile(layoutPath);
|
|
5677
5683
|
if (mod?.default) ctx.layoutStack = [{ path: layoutPath, component: mod.default }];
|
|
5684
|
+
ctx.rootLayoutBase = (ctx.mountPath || "").replace(/\/$/, "");
|
|
5678
5685
|
return next(req, ctx);
|
|
5679
5686
|
});
|
|
5680
5687
|
if (existsSync5(join5(resolved, "app.css"))) {
|
package/dist/stream.d.ts
CHANGED