@vistagenic/vista 0.2.6 → 0.2.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.
|
@@ -295,8 +295,39 @@ function getCSSLinks(cwd) {
|
|
|
295
295
|
}
|
|
296
296
|
return links.join('\n ');
|
|
297
297
|
}
|
|
298
|
+
function getChunkScripts(cwd) {
|
|
299
|
+
const chunksDir = path_1.default.join(cwd, constants_1.BUILD_DIR, 'static', 'chunks');
|
|
300
|
+
try {
|
|
301
|
+
if (!fs_1.default.existsSync(chunksDir)) {
|
|
302
|
+
return '';
|
|
303
|
+
}
|
|
304
|
+
const files = fs_1.default
|
|
305
|
+
.readdirSync(chunksDir)
|
|
306
|
+
.filter((entry) => entry.endsWith('.js') && !entry.endsWith('.map') && !entry.includes('.hot-update.'));
|
|
307
|
+
const priority = ['webpack.js', 'framework.js', 'vendor.js'];
|
|
308
|
+
files.sort((a, b) => {
|
|
309
|
+
const ai = priority.indexOf(a);
|
|
310
|
+
const bi = priority.indexOf(b);
|
|
311
|
+
if (ai !== -1 && bi !== -1)
|
|
312
|
+
return ai - bi;
|
|
313
|
+
if (ai !== -1)
|
|
314
|
+
return -1;
|
|
315
|
+
if (bi !== -1)
|
|
316
|
+
return 1;
|
|
317
|
+
return a.localeCompare(b);
|
|
318
|
+
});
|
|
319
|
+
return files
|
|
320
|
+
.map((file) => `<script defer src="${constants_1.STATIC_CHUNKS_PATH}${file}"></script>`)
|
|
321
|
+
.join('\n ');
|
|
322
|
+
}
|
|
323
|
+
catch {
|
|
324
|
+
// Ignore chunk discovery failures during static generation.
|
|
325
|
+
return '';
|
|
326
|
+
}
|
|
327
|
+
}
|
|
298
328
|
function wrapInDocument(bodyHtml, _urlPath, metadataHtml, cwd) {
|
|
299
329
|
const headInjection = `\n <meta charset="utf-8" />\n <meta name="viewport" content="width=device-width, initial-scale=1" />\n ${metadataHtml}\n ${getCSSLinks(cwd)}`;
|
|
330
|
+
const scripts = getChunkScripts(cwd);
|
|
300
331
|
const hasDocumentMarkup = /<html(?:\s|>)/i.test(bodyHtml) && /<\/html>/i.test(bodyHtml);
|
|
301
332
|
if (hasDocumentMarkup) {
|
|
302
333
|
const htmlStart = bodyHtml.search(/<html(?:\s|>)/i);
|
|
@@ -305,6 +336,8 @@ function wrapInDocument(bodyHtml, _urlPath, metadataHtml, cwd) {
|
|
|
305
336
|
html = `<!DOCTYPE html>\n${html}`;
|
|
306
337
|
}
|
|
307
338
|
html = injectBeforeClosingTag(html, 'head', headInjection);
|
|
339
|
+
const bodyInjection = `\n <script>window.${constants_1.HYDRATE_DOCUMENT_FLAG} = true;</script>\n ${scripts}`;
|
|
340
|
+
html = injectBeforeClosingTag(html, 'body', bodyInjection);
|
|
308
341
|
return html;
|
|
309
342
|
}
|
|
310
343
|
return `<!DOCTYPE html>
|
|
@@ -313,7 +346,9 @@ function wrapInDocument(bodyHtml, _urlPath, metadataHtml, cwd) {
|
|
|
313
346
|
${headInjection}
|
|
314
347
|
</head>
|
|
315
348
|
<body>
|
|
349
|
+
<script>window.${constants_1.HYDRATE_DOCUMENT_FLAG} = false;</script>
|
|
316
350
|
<div id="root">${bodyHtml}</div>
|
|
351
|
+
${scripts}
|
|
317
352
|
</body>
|
|
318
353
|
</html>`;
|
|
319
354
|
}
|