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

fix: add typescript support in .svelte files #277

Merged
merged 3 commits into from
Dec 31, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changes/fix-typescript-in-svelte-and-sveltekit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"create-tauri-app": patch
---

Fixed an [issue](https://github.com/tauri-apps/create-tauri-app/issues/276) where typescript was not working inside .svelte files in the svelte-kit-ts and svelte-ts templates. In both cases, this was due to the lack of a preprocessor. This was fixed differently in each template.

For sveltekit, the preprocessor was added to the svelte.config.js file. For svelte, the preprocessor was added to the vite.config.js file. For svelte, this required adding svelte-preprocess as a dev dependency.
lumirth marked this conversation as resolved.
Show resolved Hide resolved
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
3 changes: 2 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,10 @@
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 })] })],
lumirth marked this conversation as resolved.
Show resolved Hide resolved

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