support .svelte or .html extensions

This commit is contained in:
Rich Harris
2019-02-08 11:34:33 -05:00
parent 8870b58766
commit 84a0ae562f
11 changed files with 51 additions and 28 deletions

View File

@@ -129,7 +129,7 @@ function generate_client_manifest(
// This file is generated by Sapper — do not edit it!
export { default as Root } from '${stringify(get_file(path_to_routes, manifest_data.root), false)}';
export { preload as root_preload } from '${manifest_data.root.has_preload ? stringify(get_file(path_to_routes, manifest_data.root), false) : './shared'}';
export { default as ErrorComponent } from '${stringify(posixify(`${path_to_routes}/_error.html`), false)}';
export { default as ErrorComponent } from '${stringify(get_file(path_to_routes, manifest_data.error), false)}';
export const ignore = [${server_routes_to_ignore.map(route => route.pattern).join(', ')}];
@@ -159,7 +159,7 @@ function generate_server_manifest(
manifest_data.components.map((component, i) =>
`import component_${i}${component.has_preload ? `, { preload as preload_${i} }` : ''} from ${stringify(get_file(path_to_routes, component))};`),
`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(get_file(path_to_routes, manifest_data.error))};`
);
const component_lookup: Record<string, number> = {};
@@ -228,15 +228,9 @@ function generate_server_manifest(
export const dev = ${dev ? 'true' : 'false'};
`.replace(/^\t{2}/gm, '').trim();
return `// This file is generated by Sapper — do not edit it!\n` + template
.replace('__BUILD__DIR__', JSON.stringify(build_dir))
.replace('__SRC__DIR__', JSON.stringify(src_dir))
.replace('__DEV__', dev ? 'true' : 'false')
.replace(/const manifest = __MANIFEST__;/, code);
}
function get_file(path_to_routes: string, component: PageComponent) {
if (component.default) return `./layout.html`;
if (component.default) return `./${component.type}.svelte`;
return posixify(`${path_to_routes}/${component.file}`);
}