Skip to content

Commit

Permalink
fix: add typescript support in .svelte files (#277)
Browse files Browse the repository at this point in the history
* fix: add typescript support in .svelte files

enable and add preprocessor for sveltekit and svelte respectively

(fix #276)

* Update .changes/fix-typescript-in-svelte-and-sveltekit.md to be more concise

Co-authored-by: Amr Bashir <amr.bashir2015@gmail.com>

* style: hand-reformat line 7 to be multi-line

Signed-off-by: Lukas <65358837+lukthony@users.noreply.github.com>

Signed-off-by: Lukas <65358837+lukthony@users.noreply.github.com>
  • Loading branch information
lumirth committed Dec 31, 2022
1 parent a525c64 commit b9034ec
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changes/fix-typescript-in-svelte-and-sveltekit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-tauri-app": patch
---

Add `svelte-process` preprocessor to `svelte-ts` and `svelte-kit-ts` templates by default so typescript can work correctly inside `.svelte` files.
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import staticAdapter from "@sveltejs/adapter-static";
import { vitePreprocess } from "@sveltejs/kit/vite";

/** @type {import('@sveltejs/kit').Config} */
const config = {
preprocess: [vitePreprocess()],
kit: {
adapter: staticAdapter(),
},
Expand Down
1 change: 1 addition & 0 deletions packages/cli/fragments/fragment-svelte-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"@tsconfig/svelte": "^3.0.0",
"svelte": "^3.54.0",
"svelte-check": "^2.10.0",
"svelte-preprocess": "^5.0.0",
"tslib": "^2.4.1",
"typescript": "^4.6.4",
"vite": "^4.0.0",
Expand Down
11 changes: 10 additions & 1 deletion packages/cli/fragments/fragment-svelte-ts/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
import { defineConfig } from "vite";
import { svelte } from "@sveltejs/vite-plugin-svelte";
import sveltePreprocess from "svelte-preprocess";

// https://vitejs.dev/config/
export default defineConfig({
plugins: [svelte()],
plugins: [
svelte({
preprocess: [
sveltePreprocess({
typescript: true,
}),
],
}),
],

// Vite options tailored for Tauri development and only applied in `tauri dev` or `tauri build`
// prevent vite from obscuring rust errors
Expand Down

0 comments on commit b9034ec

Please sign in to comment.