Skip to content

Commit

Permalink
feat!: Add support for Svelte 4 (#297)
Browse files Browse the repository at this point in the history
  • Loading branch information
userquin committed Sep 2, 2023
1 parent 2461e94 commit 263a9ef
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 21 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ Type Declarations
For SvelteKit, in the `src/app.d.ts` file:

```ts
import 'unplugin-icons/types/svelte'
import 'unplugin-icons/types/svelte';
```

For Svelte + Vite, in the `src/vite-env.d.ts` file:
Expand All @@ -510,6 +510,13 @@ For Svelte + Vite, in the `src/vite-env.d.ts` file:
/// <reference types="unplugin-icons/types/svelte" />
```

If you're still using Svelte 3, replace the reference to use Svelte 3:
```js
/// <reference types="svelte" />
/// <reference types="vite/client" />
/// <reference types="unplugin-icons/types/svelte3" />
```

<br></details>

<details>
Expand Down
5 changes: 2 additions & 3 deletions examples/sveltekit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"private": true,
"scripts": {
"build": "vite build",
"check": "sveltekit sync && svelte-check --tsconfig ./tsconfig.json",
"check:watch": "sveltekit sync && svelte-check --tsconfig ./tsconfig.json --watch",
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
"dev": "vite dev",
"preview": "vite preview"
},
Expand All @@ -15,7 +15,6 @@
"@sveltejs/kit": "^1.20.4",
"svelte": "^4.2.0",
"svelte-check": "^3.5.0",
"svelte-preprocess": "^5.0.4",
"tslib": "^2.6.2",
"typescript": "^5.2.2",
"unplugin-icons": "workspace:*"
Expand Down
14 changes: 12 additions & 2 deletions examples/sveltekit/src/app.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
/// <reference types="@sveltejs/kit" />
/// <reference types="unplugin-icons/types/svelte" />
import 'unplugin-icons/types/svelte';

declare global {
namespace App {
// interface Error {}
// interface Locals {}
// interface PageData {}
// interface Platform {}
}
}

export {};
4 changes: 2 additions & 2 deletions examples/sveltekit/svelte.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import preprocess from 'svelte-preprocess'
import { vitePreprocess } from '@sveltejs/kit/vite'

/** @type {import('@sveltejs/kit').Config} */
const config = {
// Consult https://github.com/sveltejs/svelte-preprocess
// for more information about preprocessors
preprocess: preprocess(),
preprocess: vitePreprocess(),
}

export default config
2 changes: 1 addition & 1 deletion examples/vite-svelte/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import App from './App.svelte'

const app = new App({
target: document.getElementById('app'),
target: document.getElementById('app')!,
})

export default app
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@
"./types/svelte": {
"types": "./types/svelte.d.ts"
},
"./types/svelte3": {
"types": "./types/svelte3.d.ts"
},
"./types/svelte4": {
"types": "./types/svelte4.d.ts"
},
"./types/vue": {
"types": "./types/vue.d.ts"
},
Expand Down
3 changes: 0 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 1 addition & 8 deletions types/svelte.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1 @@
declare module 'virtual:icons/*' {
export { SvelteComponentDev as default } from 'svelte/internal'
}

declare module '~icons/*' {
import { SvelteComponentTyped } from 'svelte'
export default class extends SvelteComponentTyped<svelte.JSX.IntrinsicElements['svg']> {}
}
import './svelte4.d.ts'
8 changes: 8 additions & 0 deletions types/svelte3.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
declare module 'virtual:icons/*' {
export { SvelteComponentDev as default } from 'svelte/internal'
}

declare module '~icons/*' {
import { SvelteComponentTyped } from 'svelte'
export default class extends SvelteComponentTyped<svelte.JSX.IntrinsicElements['svg']> {}
}
11 changes: 11 additions & 0 deletions types/svelte4.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
declare module 'virtual:icons/*' {
import { SvelteComponent } from 'svelte'
import type { SvelteHTMLElements } from 'svelte/elements'
export default class extends SvelteComponent<SvelteHTMLElements['svg']> {}
}

declare module '~icons/*' {
import { SvelteComponent } from 'svelte'
import type { SvelteHTMLElements } from 'svelte/elements'
export default class extends SvelteComponent<SvelteHTMLElements['svg']> {}
}
2 changes: 1 addition & 1 deletion types/vue.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
import './vue3'
import './vue3.d.ts'

0 comments on commit 263a9ef

Please sign in to comment.