Add svelte as a view engine to swaf #33

Merged
ashpie merged 97 commits from svelte into develop 2021-11-09 19:31:22 +01:00
3 changed files with 17 additions and 1 deletions
Showing only changes of commit 7b2cdb8269 - Show all commits

View File

@ -317,6 +317,7 @@ export default class SvelteViewEngine extends ViewEngine {
}); });
const locals = this.getGlobals(); const locals = this.getGlobals();
delete require.cache[path.resolve(file)];
return requireFromString(svelteSsr.js.code, file).default.render({ return requireFromString(svelteSsr.js.code, file).default.render({
swaf: (key: string, args?: unknown[]) => { swaf: (key: string, args?: unknown[]) => {
if (!args) return locals[key]; if (!args) return locals[key];

View File

@ -24,7 +24,11 @@
} }
</style> </style>
<Layout title="Home"/> <Layout title="Home">
<svelte:fragment slot="body">
<h1>BONJOUR lol</h1>
</svelte:fragment>
</Layout>
<h1>Hello {count}!</h1> <h1>Hello {count}!</h1>

View File

@ -4,6 +4,12 @@
export let refresh_after = undefined; export let refresh_after = undefined;
</script> </script>
<style>
.body {
border: 1px solid blue;
}
</style>
<svelte:head> <svelte:head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0"> <meta name="viewport" content="width=device-width,initial-scale=1.0">
@ -21,3 +27,8 @@
<meta http-equiv="refresh" content={refresh_after}> <meta http-equiv="refresh" content={refresh_after}>
{/if} {/if}
</svelte:head> </svelte:head>
<div class="body">
hello
<slot name="body"/>
</div>