Fix Svelte build output (#201)
* fix(#200): svelte build output * chore: add changeset
This commit is contained in:
parent
3ef1b01e14
commit
000464bf35
4 changed files with 14 additions and 8 deletions
5
.changeset/healthy-ants-whisper.md
Normal file
5
.changeset/healthy-ants-whisper.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': patch
|
||||
---
|
||||
|
||||
Fix bug when building Svelte components
|
|
@ -2,6 +2,6 @@
|
|||
const { __astro_component: Component, __astro_children, ...props } = $$props;
|
||||
</script>
|
||||
|
||||
<Component {...props}>
|
||||
<svelte:component this={Component} {...props}>
|
||||
{@html __astro_children}
|
||||
</Component>
|
||||
</svelte:component>
|
||||
|
|
|
@ -14,7 +14,6 @@ const defaultConfig = {
|
|||
target: 'node14',
|
||||
sourcemap: 'inline',
|
||||
sourcesContent: false,
|
||||
plugins: [svelte()],
|
||||
};
|
||||
|
||||
export default async function build(...args) {
|
||||
|
@ -38,6 +37,7 @@ export default async function build(...args) {
|
|||
outdir,
|
||||
external,
|
||||
format,
|
||||
plugins: [svelte({ isDev })]
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
@ -61,6 +61,7 @@ export default async function build(...args) {
|
|||
outdir,
|
||||
external,
|
||||
format,
|
||||
plugins: [svelte({ isDev })]
|
||||
});
|
||||
|
||||
process.on('beforeExit', () => {
|
||||
|
|
|
@ -15,13 +15,13 @@ const convertMessage = ({ message, start, end, filename, frame }) => ({
|
|||
},
|
||||
});
|
||||
|
||||
const handleLoad = async (args, generate) => {
|
||||
const handleLoad = async (args, generate, { isDev }) => {
|
||||
const { path } = args;
|
||||
const source = await fs.readFile(path, 'utf8');
|
||||
const filename = relative(process.cwd(), path);
|
||||
|
||||
try {
|
||||
let compileOptions = { css: false, generate, hydratable: true };
|
||||
let compileOptions = { dev: isDev, css: false, generate, hydratable: true };
|
||||
|
||||
let { js, warnings } = compile(source, { ...compileOptions, filename });
|
||||
let contents = js.code + `\n//# sourceMappingURL=` + js.map.toUrl();
|
||||
|
@ -32,7 +32,7 @@ const handleLoad = async (args, generate) => {
|
|||
}
|
||||
};
|
||||
|
||||
export default function sveltePlugin() {
|
||||
export default function sveltePlugin({ isDev = false }) {
|
||||
return {
|
||||
name: 'svelte-esbuild',
|
||||
setup(build) {
|
||||
|
@ -54,8 +54,8 @@ export default function sveltePlugin() {
|
|||
};
|
||||
}
|
||||
});
|
||||
build.onLoad({ filter: /.*/, namespace: 'svelte:client' }, (args) => handleLoad(args, 'dom'));
|
||||
build.onLoad({ filter: /.*/, namespace: 'svelte:server' }, (args) => handleLoad(args, 'ssr'));
|
||||
build.onLoad({ filter: /.*/, namespace: 'svelte:client' }, (args) => handleLoad(args, 'dom', { isDev }));
|
||||
build.onLoad({ filter: /.*/, namespace: 'svelte:server' }, (args) => handleLoad(args, 'ssr', { isDev }));
|
||||
},
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue