Skip to content

Commit

Permalink
Support custom svelte compiler options in @astrojs/svelte (withastro#…
Browse files Browse the repository at this point in the history
…3181)

* updating svelte integration to allow custom user config

* test: adding a test to verify that svelte options are piped through the integration

* updating the README with docs on overridding svelte options

* chore: adding changeset

* fix: copy/paste bug in test validation

* removing temporary debug scripts
  • Loading branch information
Tony Sullivan authored Apr 22, 2022
1 parent 7729ff4 commit d789626
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
4 changes: 3 additions & 1 deletion test/fixtures/svelte-component/astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@ import svelte from '@astrojs/svelte';

// https://astro.build/config
export default defineConfig({
integrations: [svelte()],
integrations: [svelte({
extensions: ['.svelte', '.sve']
})],
});
5 changes: 5 additions & 0 deletions test/fixtures/svelte-component/src/components/Custom.sve
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<script lang="ts">
export let message: string;
</script>

<div id="svelte-custom-ext">{ message }</div>
5 changes: 5 additions & 0 deletions test/fixtures/svelte-component/src/pages/typescript.astro
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
---
import TypeScript from '../components/TypeScript.svelte'
// Using a custom extension to verify svelte options
// in astro.config.mjs are passed properly to the svelte integration
import Custom from '../components/Custom.sve'
---
<html lang="en">
<head>
Expand All @@ -20,6 +24,7 @@ import TypeScript from '../components/TypeScript.svelte'
<body>
<main>
<TypeScript message="Hello, TypeScript" client:load />
<Custom message="Hello, Custom Extensions" client:idle />
</main>
</body>
</html>
7 changes: 7 additions & 0 deletions test/svelte-component.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ describe('Svelte component', () => {

expect($('#svelte-ts').text()).to.equal('Hello, TypeScript');
});

it('Works with custom Svelte config', async () => {
const html = await fixture.readFile('/typescript/index.html');
const $ = cheerio.load(html);

expect($('#svelte-custom-ext').text()).to.equal('Hello, Custom Extensions');
});
});

if (isWindows) return;
Expand Down

0 comments on commit d789626

Please sign in to comment.