Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: Add support for Svelte 4 #297

Merged
merged 15 commits into from
Sep 2, 2023
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
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'
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

node module resolution needs the file to be there

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'