Skip to content

Commit 263a9ef

Browse files
authoredSep 2, 2023
feat!: Add support for Svelte 4 (#297)
1 parent 2461e94 commit 263a9ef

File tree

11 files changed

+52
-21
lines changed

11 files changed

+52
-21
lines changed
 

‎README.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ Type Declarations
499499
For SvelteKit, in the `src/app.d.ts` file:
500500

501501
```ts
502-
import 'unplugin-icons/types/svelte'
502+
import 'unplugin-icons/types/svelte';
503503
```
504504

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

513+
If you're still using Svelte 3, replace the reference to use Svelte 3:
514+
```js
515+
/// <reference types="svelte" />
516+
/// <reference types="vite/client" />
517+
/// <reference types="unplugin-icons/types/svelte3" />
518+
```
519+
513520
<br></details>
514521

515522
<details>

‎examples/sveltekit/package.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"private": true,
44
"scripts": {
55
"build": "vite build",
6-
"check": "sveltekit sync && svelte-check --tsconfig ./tsconfig.json",
7-
"check:watch": "sveltekit sync && svelte-check --tsconfig ./tsconfig.json --watch",
6+
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
7+
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
88
"dev": "vite dev",
99
"preview": "vite preview"
1010
},
@@ -15,7 +15,6 @@
1515
"@sveltejs/kit": "^1.20.4",
1616
"svelte": "^4.2.0",
1717
"svelte-check": "^3.5.0",
18-
"svelte-preprocess": "^5.0.4",
1918
"tslib": "^2.6.2",
2019
"typescript": "^5.2.2",
2120
"unplugin-icons": "workspace:*"

‎examples/sveltekit/src/app.d.ts

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,12 @@
1-
/// <reference types="@sveltejs/kit" />
2-
/// <reference types="unplugin-icons/types/svelte" />
1+
import 'unplugin-icons/types/svelte';
2+
3+
declare global {
4+
namespace App {
5+
// interface Error {}
6+
// interface Locals {}
7+
// interface PageData {}
8+
// interface Platform {}
9+
}
10+
}
11+
12+
export {};

‎examples/sveltekit/svelte.config.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import preprocess from 'svelte-preprocess'
1+
import { vitePreprocess } from '@sveltejs/kit/vite'
22

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

1010
export default config

‎examples/vite-svelte/src/main.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import App from './App.svelte'
22

33
const app = new App({
4-
target: document.getElementById('app'),
4+
target: document.getElementById('app')!,
55
})
66

77
export default app

‎package.json

+6
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@
6868
"./types/svelte": {
6969
"types": "./types/svelte.d.ts"
7070
},
71+
"./types/svelte3": {
72+
"types": "./types/svelte3.d.ts"
73+
},
74+
"./types/svelte4": {
75+
"types": "./types/svelte4.d.ts"
76+
},
7177
"./types/vue": {
7278
"types": "./types/vue.d.ts"
7379
},

‎pnpm-lock.yaml

-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎types/svelte.d.ts

+1-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1 @@
1-
declare module 'virtual:icons/*' {
2-
export { SvelteComponentDev as default } from 'svelte/internal'
3-
}
4-
5-
declare module '~icons/*' {
6-
import { SvelteComponentTyped } from 'svelte'
7-
export default class extends SvelteComponentTyped<svelte.JSX.IntrinsicElements['svg']> {}
8-
}
1+
import './svelte4.d.ts'

‎types/svelte3.d.ts

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
declare module 'virtual:icons/*' {
2+
export { SvelteComponentDev as default } from 'svelte/internal'
3+
}
4+
5+
declare module '~icons/*' {
6+
import { SvelteComponentTyped } from 'svelte'
7+
export default class extends SvelteComponentTyped<svelte.JSX.IntrinsicElements['svg']> {}
8+
}

‎types/svelte4.d.ts

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
declare module 'virtual:icons/*' {
2+
import { SvelteComponent } from 'svelte'
3+
import type { SvelteHTMLElements } from 'svelte/elements'
4+
export default class extends SvelteComponent<SvelteHTMLElements['svg']> {}
5+
}
6+
7+
declare module '~icons/*' {
8+
import { SvelteComponent } from 'svelte'
9+
import type { SvelteHTMLElements } from 'svelte/elements'
10+
export default class extends SvelteComponent<SvelteHTMLElements['svg']> {}
11+
}

‎types/vue.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
import './vue3'
1+
import './vue3.d.ts'

0 commit comments

Comments
 (0)
Please sign in to comment.