@sveltejs/kit 1.0.0-next.224 → 1.0.0-next.225
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/assets/kit.js +67 -80
- package/dist/chunks/index.js +4 -3
- package/dist/chunks/index2.js +1 -15
- package/dist/chunks/index3.js +39 -17
- package/dist/cli.js +4 -2
- package/dist/ssr.js +67 -80
- package/package.json +1 -1
- package/types/config.d.ts +1 -0
- package/types/internal.d.ts +1 -1
package/assets/kit.js
CHANGED
|
@@ -567,7 +567,8 @@ async function render_response({
|
|
|
567
567
|
}) {
|
|
568
568
|
const css = new Set(options.manifest._.entry.css);
|
|
569
569
|
const js = new Set(options.manifest._.entry.js);
|
|
570
|
-
|
|
570
|
+
/** @type {Map<string, string>} */
|
|
571
|
+
const styles = new Map();
|
|
571
572
|
|
|
572
573
|
/** @type {Array<{ url: string, body: string, json: string }>} */
|
|
573
574
|
const serialized_data = [];
|
|
@@ -585,7 +586,7 @@ async function render_response({
|
|
|
585
586
|
branch.forEach(({ node, loaded, fetched, uses_credentials }) => {
|
|
586
587
|
if (node.css) node.css.forEach((url) => css.add(url));
|
|
587
588
|
if (node.js) node.js.forEach((url) => js.add(url));
|
|
588
|
-
if (node.styles) node.styles.forEach((
|
|
589
|
+
if (node.styles) Object.entries(node.styles).forEach(([k, v]) => styles.set(k, v));
|
|
589
590
|
|
|
590
591
|
// TODO probably better if `fetched` wasn't populated unless `hydrate`
|
|
591
592
|
if (fetched && page_config.hydrate) serialized_data.push(...fetched);
|
|
@@ -646,94 +647,80 @@ async function render_response({
|
|
|
646
647
|
rendered = { head: '', html: '', css: { code: '', map: null } };
|
|
647
648
|
}
|
|
648
649
|
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
// TODO strip the AMP stuff out of the build if not relevant
|
|
653
|
-
const links = options.amp
|
|
654
|
-
? styles.size > 0 || rendered.css.code.length > 0
|
|
655
|
-
? `<style amp-custom>${Array.from(styles).concat(rendered.css.code).join('\n')}</style>`
|
|
656
|
-
: ''
|
|
657
|
-
: [
|
|
658
|
-
// From https://web.dev/priority-hints/:
|
|
659
|
-
// Generally, preloads will load in the order the parser gets to them for anything above "Medium" priority
|
|
660
|
-
// Thus, we should list CSS first
|
|
661
|
-
...Array.from(css).map((dep) => `<link rel="stylesheet" href="${options.prefix}${dep}">`),
|
|
662
|
-
...Array.from(js).map((dep) => `<link rel="modulepreload" href="${options.prefix}${dep}">`)
|
|
663
|
-
].join('\n\t\t');
|
|
664
|
-
|
|
665
|
-
/** @type {string} */
|
|
666
|
-
let init = '';
|
|
650
|
+
let { head, html: body } = rendered;
|
|
651
|
+
|
|
652
|
+
const inlined_style = Array.from(styles.values()).join('\n');
|
|
667
653
|
|
|
668
654
|
if (options.amp) {
|
|
669
|
-
|
|
655
|
+
head += `
|
|
670
656
|
<style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style>
|
|
671
657
|
<noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript>
|
|
672
|
-
<script async src="https://cdn.ampproject.org/v0.js"></script
|
|
673
|
-
init += options.service_worker
|
|
674
|
-
? '<script async custom-element="amp-install-serviceworker" src="https://cdn.ampproject.org/v0/amp-install-serviceworker-0.1.js"></script>'
|
|
675
|
-
: '';
|
|
676
|
-
} else if (include_js) {
|
|
677
|
-
// prettier-ignore
|
|
678
|
-
init = `<script type="module">
|
|
679
|
-
import { start } from ${s(options.prefix + options.manifest._.entry.file)};
|
|
680
|
-
start({
|
|
681
|
-
target: ${options.target ? `document.querySelector(${s(options.target)})` : 'document.body'},
|
|
682
|
-
paths: ${s(options.paths)},
|
|
683
|
-
session: ${try_serialize($session, (error) => {
|
|
684
|
-
throw new Error(`Failed to serialize session data: ${error.message}`);
|
|
685
|
-
})},
|
|
686
|
-
route: ${!!page_config.router},
|
|
687
|
-
spa: ${!ssr},
|
|
688
|
-
trailing_slash: ${s(options.trailing_slash)},
|
|
689
|
-
hydrate: ${ssr && page_config.hydrate ? `{
|
|
690
|
-
status: ${status},
|
|
691
|
-
error: ${serialize_error(error)},
|
|
692
|
-
nodes: [
|
|
693
|
-
${(branch || [])
|
|
694
|
-
.map(({ node }) => `import(${s(options.prefix + node.entry)})`)
|
|
695
|
-
.join(',\n\t\t\t\t\t\t')}
|
|
696
|
-
],
|
|
697
|
-
url: new URL(${s(url.href)}),
|
|
698
|
-
params: ${devalue(params)}
|
|
699
|
-
}` : 'null'}
|
|
700
|
-
});
|
|
701
|
-
</script>`;
|
|
702
|
-
}
|
|
703
|
-
|
|
704
|
-
if (options.service_worker && !options.amp) {
|
|
705
|
-
init += `<script>
|
|
706
|
-
if ('serviceWorker' in navigator) {
|
|
707
|
-
navigator.serviceWorker.register('${options.service_worker}');
|
|
708
|
-
}
|
|
709
|
-
</script>`;
|
|
710
|
-
}
|
|
658
|
+
<script async src="https://cdn.ampproject.org/v0.js"></script>
|
|
711
659
|
|
|
712
|
-
|
|
713
|
-
rendered.head,
|
|
714
|
-
styles.size && !options.amp
|
|
715
|
-
? `<style data-svelte>${Array.from(styles).join('\n')}</style>`
|
|
716
|
-
: '',
|
|
717
|
-
links,
|
|
718
|
-
init
|
|
719
|
-
].join('\n\n\t\t');
|
|
660
|
+
<style amp-custom>${inlined_style}\n${rendered.css.code}</style>`;
|
|
720
661
|
|
|
721
|
-
let body = rendered.html;
|
|
722
|
-
if (options.amp) {
|
|
723
662
|
if (options.service_worker) {
|
|
663
|
+
head +=
|
|
664
|
+
'<script async custom-element="amp-install-serviceworker" src="https://cdn.ampproject.org/v0/amp-install-serviceworker-0.1.js"></script>';
|
|
665
|
+
|
|
724
666
|
body += `<amp-install-serviceworker src="${options.service_worker}" layout="nodisplay"></amp-install-serviceworker>`;
|
|
725
667
|
}
|
|
726
668
|
} else {
|
|
727
|
-
|
|
728
|
-
.
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
.
|
|
669
|
+
if (inlined_style) {
|
|
670
|
+
head += `\n\t<style${options.dev ? ' data-svelte' : ''}>${inlined_style}</style>`;
|
|
671
|
+
}
|
|
672
|
+
// prettier-ignore
|
|
673
|
+
head += Array.from(css)
|
|
674
|
+
.map((dep) => `\n\t<link${styles.has(dep) ? ' disabled' : ''} rel="stylesheet" href="${options.prefix + dep}">`)
|
|
675
|
+
.join('');
|
|
676
|
+
|
|
677
|
+
if (page_config.router || page_config.hydrate) {
|
|
678
|
+
head += Array.from(js)
|
|
679
|
+
.map((dep) => `\n\t<link rel="modulepreload" href="${options.prefix + dep}">`)
|
|
680
|
+
.join('');
|
|
681
|
+
// prettier-ignore
|
|
682
|
+
head += `
|
|
683
|
+
<script type="module">
|
|
684
|
+
import { start } from ${s(options.prefix + options.manifest._.entry.file)};
|
|
685
|
+
start({
|
|
686
|
+
target: ${options.target ? `document.querySelector(${s(options.target)})` : 'document.body'},
|
|
687
|
+
paths: ${s(options.paths)},
|
|
688
|
+
session: ${try_serialize($session, (error) => {
|
|
689
|
+
throw new Error(`Failed to serialize session data: ${error.message}`);
|
|
690
|
+
})},
|
|
691
|
+
route: ${!!page_config.router},
|
|
692
|
+
spa: ${!ssr},
|
|
693
|
+
trailing_slash: ${s(options.trailing_slash)},
|
|
694
|
+
hydrate: ${ssr && page_config.hydrate ? `{
|
|
695
|
+
status: ${status},
|
|
696
|
+
error: ${serialize_error(error)},
|
|
697
|
+
nodes: [
|
|
698
|
+
${(branch || [])
|
|
699
|
+
.map(({ node }) => `import(${s(options.prefix + node.entry)})`)
|
|
700
|
+
.join(',\n\t\t\t\t\t\t')}
|
|
701
|
+
],
|
|
702
|
+
url: new URL(${s(url.href)}),
|
|
703
|
+
params: ${devalue(params)}
|
|
704
|
+
}` : 'null'}
|
|
705
|
+
});
|
|
706
|
+
</script>${options.service_worker ? `
|
|
707
|
+
<script>
|
|
708
|
+
if ('serviceWorker' in navigator) {
|
|
709
|
+
navigator.serviceWorker.register('${options.service_worker}');
|
|
710
|
+
}
|
|
711
|
+
</script>` : ''}`;
|
|
712
|
+
|
|
713
|
+
body += serialized_data
|
|
714
|
+
.map(({ url, body, json }) => {
|
|
715
|
+
let attributes = `type="application/json" data-type="svelte-data" data-url=${escape_html_attr(
|
|
716
|
+
url
|
|
717
|
+
)}`;
|
|
718
|
+
if (body) attributes += ` data-body="${hash(body)}"`;
|
|
719
|
+
|
|
720
|
+
return `<script ${attributes}>${json}</script>`;
|
|
721
|
+
})
|
|
722
|
+
.join('\n\n\t');
|
|
723
|
+
}
|
|
737
724
|
}
|
|
738
725
|
|
|
739
726
|
/** @type {import('types/helper').ResponseHeaders} */
|
package/dist/chunks/index.js
CHANGED
|
@@ -76,7 +76,8 @@ async function create_plugin(config, output, cwd) {
|
|
|
76
76
|
const deps = new Set();
|
|
77
77
|
find_deps(node, deps);
|
|
78
78
|
|
|
79
|
-
|
|
79
|
+
/** @type {Record<string, string>} */
|
|
80
|
+
const styles = {};
|
|
80
81
|
|
|
81
82
|
for (const dep of deps) {
|
|
82
83
|
const parsed = new URL(dep.url, 'http://localhost/');
|
|
@@ -89,7 +90,7 @@ async function create_plugin(config, output, cwd) {
|
|
|
89
90
|
) {
|
|
90
91
|
try {
|
|
91
92
|
const mod = await vite.ssrLoadModule(dep.url);
|
|
92
|
-
styles.
|
|
93
|
+
styles[dep.url] = mod.default;
|
|
93
94
|
} catch {
|
|
94
95
|
// this can happen with dynamically imported modules, I think
|
|
95
96
|
// because the Vite module graph doesn't distinguish between
|
|
@@ -103,7 +104,7 @@ async function create_plugin(config, output, cwd) {
|
|
|
103
104
|
entry: url.endsWith('.svelte') ? url : url + '?import',
|
|
104
105
|
css: [],
|
|
105
106
|
js: [],
|
|
106
|
-
styles
|
|
107
|
+
styles
|
|
107
108
|
};
|
|
108
109
|
};
|
|
109
110
|
}),
|
package/dist/chunks/index2.js
CHANGED
|
@@ -260,26 +260,12 @@ function generate_app(manifest_data) {
|
|
|
260
260
|
${pyramid.replace(/\n/g, '\n\t\t')}
|
|
261
261
|
|
|
262
262
|
{#if mounted}
|
|
263
|
-
<div id="svelte-announcer" aria-live="assertive" aria-atomic="true">
|
|
263
|
+
<div id="svelte-announcer" aria-live="assertive" aria-atomic="true" style="position: absolute; left: 0; top: 0; clip: rect(0 0 0 0); clip-path: inset(50%); overflow: hidden; white-space: nowrap; width: 1px; height: 1px">
|
|
264
264
|
{#if navigated}
|
|
265
265
|
{title}
|
|
266
266
|
{/if}
|
|
267
267
|
</div>
|
|
268
268
|
{/if}
|
|
269
|
-
|
|
270
|
-
<style>
|
|
271
|
-
#svelte-announcer {
|
|
272
|
-
position: absolute;
|
|
273
|
-
left: 0;
|
|
274
|
-
top: 0;
|
|
275
|
-
clip: rect(0 0 0 0);
|
|
276
|
-
clip-path: inset(50%);
|
|
277
|
-
overflow: hidden;
|
|
278
|
-
white-space: nowrap;
|
|
279
|
-
width: 1px;
|
|
280
|
-
height: 1px;
|
|
281
|
-
}
|
|
282
|
-
</style>
|
|
283
269
|
`);
|
|
284
270
|
}
|
|
285
271
|
|
package/dist/chunks/index3.js
CHANGED
|
@@ -499,16 +499,23 @@ async function build_server(
|
|
|
499
499
|
/** @type {import('vite').Manifest} */
|
|
500
500
|
const vite_manifest = JSON.parse(fs__default.readFileSync(`${output_dir}/server/manifest.json`, 'utf-8'));
|
|
501
501
|
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
502
|
+
mkdirp(`${output_dir}/server/nodes`);
|
|
503
|
+
mkdirp(`${output_dir}/server/stylesheets`);
|
|
504
|
+
|
|
505
|
+
const stylesheet_lookup = new Map();
|
|
506
|
+
|
|
507
|
+
client.assets.forEach((asset) => {
|
|
508
|
+
if (asset.fileName.endsWith('.css')) {
|
|
509
|
+
if (config.kit.amp || asset.source.length < config.kit.inlineStyleThreshold) {
|
|
510
|
+
const index = stylesheet_lookup.size;
|
|
511
|
+
const file = `${output_dir}/server/stylesheets/${index}.js`;
|
|
512
|
+
|
|
513
|
+
fs__default.writeFileSync(file, `// ${asset.fileName}\nexport default ${s(asset.source)};`);
|
|
514
|
+
stylesheet_lookup.set(asset.fileName, index);
|
|
507
515
|
}
|
|
508
|
-
}
|
|
509
|
-
}
|
|
516
|
+
}
|
|
517
|
+
});
|
|
510
518
|
|
|
511
|
-
mkdirp(`${output_dir}/server/nodes`);
|
|
512
519
|
manifest_data.components.forEach((component, i) => {
|
|
513
520
|
const file = `${output_dir}/server/nodes/${i}.js`;
|
|
514
521
|
|
|
@@ -516,17 +523,32 @@ async function build_server(
|
|
|
516
523
|
const css = new Set();
|
|
517
524
|
find_deps(component, client.vite_manifest, js, css);
|
|
518
525
|
|
|
519
|
-
const
|
|
526
|
+
const imports = [`import * as module from '../${vite_manifest[component].file}';`];
|
|
527
|
+
|
|
528
|
+
const exports = [
|
|
529
|
+
'export { module };',
|
|
530
|
+
`export const entry = '${client.vite_manifest[component].file}';`,
|
|
531
|
+
`export const js = ${s(Array.from(js))};`,
|
|
532
|
+
`export const css = ${s(Array.from(css))};`
|
|
533
|
+
];
|
|
520
534
|
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
535
|
+
/** @type {string[]} */
|
|
536
|
+
const styles = [];
|
|
537
|
+
|
|
538
|
+
css.forEach((file) => {
|
|
539
|
+
if (stylesheet_lookup.has(file)) {
|
|
540
|
+
const index = stylesheet_lookup.get(file);
|
|
541
|
+
const name = `stylesheet_${index}`;
|
|
542
|
+
imports.push(`import ${name} from '../stylesheets/${index}.js';`);
|
|
543
|
+
styles.push(`\t${s(file)}: ${name}`);
|
|
544
|
+
}
|
|
545
|
+
});
|
|
546
|
+
|
|
547
|
+
if (styles.length > 0) {
|
|
548
|
+
exports.push(`export const styles = {\n${styles.join(',\n')}\n};`);
|
|
549
|
+
}
|
|
528
550
|
|
|
529
|
-
fs__default.writeFileSync(file,
|
|
551
|
+
fs__default.writeFileSync(file, `${imports.join('\n')}\n\n${exports.join('\n')}\n`);
|
|
530
552
|
});
|
|
531
553
|
|
|
532
554
|
return {
|
package/dist/cli.js
CHANGED
|
@@ -479,6 +479,8 @@ const options = object(
|
|
|
479
479
|
|
|
480
480
|
hydrate: boolean(true),
|
|
481
481
|
|
|
482
|
+
inlineStyleThreshold: number(0),
|
|
483
|
+
|
|
482
484
|
methodOverride: object({
|
|
483
485
|
parameter: string('_method'),
|
|
484
486
|
allowed: validate([], (input, keypath) => {
|
|
@@ -868,7 +870,7 @@ async function launch(port, https) {
|
|
|
868
870
|
exec(`${cmd} ${https ? 'https' : 'http'}://localhost:${port}`);
|
|
869
871
|
}
|
|
870
872
|
|
|
871
|
-
const prog = sade('svelte-kit').version('1.0.0-next.
|
|
873
|
+
const prog = sade('svelte-kit').version('1.0.0-next.225');
|
|
872
874
|
|
|
873
875
|
prog
|
|
874
876
|
.command('dev')
|
|
@@ -1020,7 +1022,7 @@ async function check_port(port) {
|
|
|
1020
1022
|
function welcome({ port, host, https, open, loose, allow, cwd }) {
|
|
1021
1023
|
if (open) launch(port, https);
|
|
1022
1024
|
|
|
1023
|
-
console.log($.bold().cyan(`\n SvelteKit v${'1.0.0-next.
|
|
1025
|
+
console.log($.bold().cyan(`\n SvelteKit v${'1.0.0-next.225'}\n`));
|
|
1024
1026
|
|
|
1025
1027
|
const protocol = https ? 'https:' : 'http:';
|
|
1026
1028
|
const exposed = typeof host !== 'undefined' && host !== 'localhost' && host !== '127.0.0.1';
|
package/dist/ssr.js
CHANGED
|
@@ -536,7 +536,8 @@ async function render_response({
|
|
|
536
536
|
}) {
|
|
537
537
|
const css = new Set(options.manifest._.entry.css);
|
|
538
538
|
const js = new Set(options.manifest._.entry.js);
|
|
539
|
-
|
|
539
|
+
/** @type {Map<string, string>} */
|
|
540
|
+
const styles = new Map();
|
|
540
541
|
|
|
541
542
|
/** @type {Array<{ url: string, body: string, json: string }>} */
|
|
542
543
|
const serialized_data = [];
|
|
@@ -554,7 +555,7 @@ async function render_response({
|
|
|
554
555
|
branch.forEach(({ node, loaded, fetched, uses_credentials }) => {
|
|
555
556
|
if (node.css) node.css.forEach((url) => css.add(url));
|
|
556
557
|
if (node.js) node.js.forEach((url) => js.add(url));
|
|
557
|
-
if (node.styles) node.styles.forEach((
|
|
558
|
+
if (node.styles) Object.entries(node.styles).forEach(([k, v]) => styles.set(k, v));
|
|
558
559
|
|
|
559
560
|
// TODO probably better if `fetched` wasn't populated unless `hydrate`
|
|
560
561
|
if (fetched && page_config.hydrate) serialized_data.push(...fetched);
|
|
@@ -615,94 +616,80 @@ async function render_response({
|
|
|
615
616
|
rendered = { head: '', html: '', css: { code: '', map: null } };
|
|
616
617
|
}
|
|
617
618
|
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
// TODO strip the AMP stuff out of the build if not relevant
|
|
622
|
-
const links = options.amp
|
|
623
|
-
? styles.size > 0 || rendered.css.code.length > 0
|
|
624
|
-
? `<style amp-custom>${Array.from(styles).concat(rendered.css.code).join('\n')}</style>`
|
|
625
|
-
: ''
|
|
626
|
-
: [
|
|
627
|
-
// From https://web.dev/priority-hints/:
|
|
628
|
-
// Generally, preloads will load in the order the parser gets to them for anything above "Medium" priority
|
|
629
|
-
// Thus, we should list CSS first
|
|
630
|
-
...Array.from(css).map((dep) => `<link rel="stylesheet" href="${options.prefix}${dep}">`),
|
|
631
|
-
...Array.from(js).map((dep) => `<link rel="modulepreload" href="${options.prefix}${dep}">`)
|
|
632
|
-
].join('\n\t\t');
|
|
633
|
-
|
|
634
|
-
/** @type {string} */
|
|
635
|
-
let init = '';
|
|
619
|
+
let { head, html: body } = rendered;
|
|
620
|
+
|
|
621
|
+
const inlined_style = Array.from(styles.values()).join('\n');
|
|
636
622
|
|
|
637
623
|
if (options.amp) {
|
|
638
|
-
|
|
624
|
+
head += `
|
|
639
625
|
<style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style>
|
|
640
626
|
<noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript>
|
|
641
|
-
<script async src="https://cdn.ampproject.org/v0.js"></script
|
|
642
|
-
init += options.service_worker
|
|
643
|
-
? '<script async custom-element="amp-install-serviceworker" src="https://cdn.ampproject.org/v0/amp-install-serviceworker-0.1.js"></script>'
|
|
644
|
-
: '';
|
|
645
|
-
} else if (include_js) {
|
|
646
|
-
// prettier-ignore
|
|
647
|
-
init = `<script type="module">
|
|
648
|
-
import { start } from ${s(options.prefix + options.manifest._.entry.file)};
|
|
649
|
-
start({
|
|
650
|
-
target: ${options.target ? `document.querySelector(${s(options.target)})` : 'document.body'},
|
|
651
|
-
paths: ${s(options.paths)},
|
|
652
|
-
session: ${try_serialize($session, (error) => {
|
|
653
|
-
throw new Error(`Failed to serialize session data: ${error.message}`);
|
|
654
|
-
})},
|
|
655
|
-
route: ${!!page_config.router},
|
|
656
|
-
spa: ${!ssr},
|
|
657
|
-
trailing_slash: ${s(options.trailing_slash)},
|
|
658
|
-
hydrate: ${ssr && page_config.hydrate ? `{
|
|
659
|
-
status: ${status},
|
|
660
|
-
error: ${serialize_error(error)},
|
|
661
|
-
nodes: [
|
|
662
|
-
${(branch || [])
|
|
663
|
-
.map(({ node }) => `import(${s(options.prefix + node.entry)})`)
|
|
664
|
-
.join(',\n\t\t\t\t\t\t')}
|
|
665
|
-
],
|
|
666
|
-
url: new URL(${s(url.href)}),
|
|
667
|
-
params: ${devalue(params)}
|
|
668
|
-
}` : 'null'}
|
|
669
|
-
});
|
|
670
|
-
</script>`;
|
|
671
|
-
}
|
|
672
|
-
|
|
673
|
-
if (options.service_worker && !options.amp) {
|
|
674
|
-
init += `<script>
|
|
675
|
-
if ('serviceWorker' in navigator) {
|
|
676
|
-
navigator.serviceWorker.register('${options.service_worker}');
|
|
677
|
-
}
|
|
678
|
-
</script>`;
|
|
679
|
-
}
|
|
627
|
+
<script async src="https://cdn.ampproject.org/v0.js"></script>
|
|
680
628
|
|
|
681
|
-
|
|
682
|
-
rendered.head,
|
|
683
|
-
styles.size && !options.amp
|
|
684
|
-
? `<style data-svelte>${Array.from(styles).join('\n')}</style>`
|
|
685
|
-
: '',
|
|
686
|
-
links,
|
|
687
|
-
init
|
|
688
|
-
].join('\n\n\t\t');
|
|
629
|
+
<style amp-custom>${inlined_style}\n${rendered.css.code}</style>`;
|
|
689
630
|
|
|
690
|
-
let body = rendered.html;
|
|
691
|
-
if (options.amp) {
|
|
692
631
|
if (options.service_worker) {
|
|
632
|
+
head +=
|
|
633
|
+
'<script async custom-element="amp-install-serviceworker" src="https://cdn.ampproject.org/v0/amp-install-serviceworker-0.1.js"></script>';
|
|
634
|
+
|
|
693
635
|
body += `<amp-install-serviceworker src="${options.service_worker}" layout="nodisplay"></amp-install-serviceworker>`;
|
|
694
636
|
}
|
|
695
637
|
} else {
|
|
696
|
-
|
|
697
|
-
.
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
.
|
|
638
|
+
if (inlined_style) {
|
|
639
|
+
head += `\n\t<style${options.dev ? ' data-svelte' : ''}>${inlined_style}</style>`;
|
|
640
|
+
}
|
|
641
|
+
// prettier-ignore
|
|
642
|
+
head += Array.from(css)
|
|
643
|
+
.map((dep) => `\n\t<link${styles.has(dep) ? ' disabled' : ''} rel="stylesheet" href="${options.prefix + dep}">`)
|
|
644
|
+
.join('');
|
|
645
|
+
|
|
646
|
+
if (page_config.router || page_config.hydrate) {
|
|
647
|
+
head += Array.from(js)
|
|
648
|
+
.map((dep) => `\n\t<link rel="modulepreload" href="${options.prefix + dep}">`)
|
|
649
|
+
.join('');
|
|
650
|
+
// prettier-ignore
|
|
651
|
+
head += `
|
|
652
|
+
<script type="module">
|
|
653
|
+
import { start } from ${s(options.prefix + options.manifest._.entry.file)};
|
|
654
|
+
start({
|
|
655
|
+
target: ${options.target ? `document.querySelector(${s(options.target)})` : 'document.body'},
|
|
656
|
+
paths: ${s(options.paths)},
|
|
657
|
+
session: ${try_serialize($session, (error) => {
|
|
658
|
+
throw new Error(`Failed to serialize session data: ${error.message}`);
|
|
659
|
+
})},
|
|
660
|
+
route: ${!!page_config.router},
|
|
661
|
+
spa: ${!ssr},
|
|
662
|
+
trailing_slash: ${s(options.trailing_slash)},
|
|
663
|
+
hydrate: ${ssr && page_config.hydrate ? `{
|
|
664
|
+
status: ${status},
|
|
665
|
+
error: ${serialize_error(error)},
|
|
666
|
+
nodes: [
|
|
667
|
+
${(branch || [])
|
|
668
|
+
.map(({ node }) => `import(${s(options.prefix + node.entry)})`)
|
|
669
|
+
.join(',\n\t\t\t\t\t\t')}
|
|
670
|
+
],
|
|
671
|
+
url: new URL(${s(url.href)}),
|
|
672
|
+
params: ${devalue(params)}
|
|
673
|
+
}` : 'null'}
|
|
674
|
+
});
|
|
675
|
+
</script>${options.service_worker ? `
|
|
676
|
+
<script>
|
|
677
|
+
if ('serviceWorker' in navigator) {
|
|
678
|
+
navigator.serviceWorker.register('${options.service_worker}');
|
|
679
|
+
}
|
|
680
|
+
</script>` : ''}`;
|
|
681
|
+
|
|
682
|
+
body += serialized_data
|
|
683
|
+
.map(({ url, body, json }) => {
|
|
684
|
+
let attributes = `type="application/json" data-type="svelte-data" data-url=${escape_html_attr(
|
|
685
|
+
url
|
|
686
|
+
)}`;
|
|
687
|
+
if (body) attributes += ` data-body="${hash(body)}"`;
|
|
688
|
+
|
|
689
|
+
return `<script ${attributes}>${json}</script>`;
|
|
690
|
+
})
|
|
691
|
+
.join('\n\n\t');
|
|
692
|
+
}
|
|
706
693
|
}
|
|
707
694
|
|
|
708
695
|
/** @type {import('types/helper').ResponseHeaders} */
|
package/package.json
CHANGED
package/types/config.d.ts
CHANGED