Installation
Install svelte-global-typescript for Vite builds and Svelte editor tooling.Install svelte-global-typescript as a development dependency.
deno add --dev npm:svelte-global-typescriptbun add --dev svelte-global-typescriptpnpm add -D svelte-global-typescriptnpm install --save-dev svelte-global-typescriptyarn add --dev svelte-global-typescriptnub add --dev svelte-global-typescriptaube add --dev svelte-global-typescriptvlt install --save-dev svelte-global-typescriptCreate one plugin instance, put it before SvelteKit in the Vite plugin list, and give the same instance to Svelte's preprocessors.
vite.config.ts
import { sveltekit } from "@sveltejs/kit/vite";
import { defineConfig } from "vite";
import { ts } from "svelte-global-typescript";
const global_typescript = ts();
export default defineConfig({
plugins: [
global_typescript,
sveltekit({
preprocess: [global_typescript],
}),
],
});Vite uses the plugin transform during builds. SvelteKit and editor tooling use the preprocessor, so passing the same value through preprocess keeps both paths consistent without a separate Svelte config file.
ts() and ts(true) are equivalent. Use ts(false) to leave the Vite plugin installed while disabling component transforms.
On this page