mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-19 22:05:20 +00:00
only import preload when appropriate
This commit is contained in:
@@ -175,13 +175,13 @@ function generate_server(
|
|||||||
manifest_data.server_routes.map(route =>
|
manifest_data.server_routes.map(route =>
|
||||||
`import * as __${route.name} from ${stringify(posixify(`${path_to_routes}/${route.file}`))};`),
|
`import * as __${route.name} from ${stringify(posixify(`${path_to_routes}/${route.file}`))};`),
|
||||||
manifest_data.components.map(component =>
|
manifest_data.components.map(component =>
|
||||||
`import __${component.name}, * as __${component.name}_static from ${stringify(get_file(path_to_routes, component))};`),
|
`import __${component.name}${component.has_preload ? `, { preload as __${component.name}_preload }` : ''} from ${stringify(get_file(path_to_routes, component))};`),
|
||||||
`import root, * as root_static from ${stringify(get_file(path_to_routes, manifest_data.root))};`,
|
`import root${manifest_data.root.has_preload ? `, { preload as root_preload }` : ''} from ${stringify(get_file(path_to_routes, manifest_data.root))};`,
|
||||||
`import error from ${stringify(posixify(`${path_to_routes}/_error.html`))};`
|
`import error from ${stringify(posixify(`${path_to_routes}/_error.html`))};`
|
||||||
);
|
);
|
||||||
|
|
||||||
let code = `
|
let code = `
|
||||||
${imports.join('\n')}
|
${imports.join('\n')}${manifest_data.root.has_preload ? '' : `\n\nconst root_preload = () => {};`}
|
||||||
|
|
||||||
const d = decodeURIComponent;
|
const d = decodeURIComponent;
|
||||||
|
|
||||||
@@ -209,8 +209,8 @@ function generate_server(
|
|||||||
`name: "${part.component.name}"`,
|
`name: "${part.component.name}"`,
|
||||||
`file: ${stringify(part.component.file)}`,
|
`file: ${stringify(part.component.file)}`,
|
||||||
`component: __${part.component.name}`,
|
`component: __${part.component.name}`,
|
||||||
`preload: __${part.component.name}_static.preload`
|
part.component.has_preload && `preload: __${part.component.name}_preload`
|
||||||
];
|
].filter(Boolean);
|
||||||
|
|
||||||
if (part.params.length > 0) {
|
if (part.params.length > 0) {
|
||||||
const params = part.params.map((param, i) => `${param}: d(match[${i + 1}])`);
|
const params = part.params.map((param, i) => `${param}: d(match[${i + 1}])`);
|
||||||
@@ -224,8 +224,7 @@ function generate_server(
|
|||||||
],
|
],
|
||||||
|
|
||||||
root,
|
root,
|
||||||
root_preload: root_static['pre' + 'load'],
|
root_preload,
|
||||||
|
|
||||||
error
|
error
|
||||||
};`.replace(/^\t\t/gm, '').trim();
|
};`.replace(/^\t\t/gm, '').trim();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user