Applies the TypeScript compiler during Vite transform build phase.
This plugin may allow the use of language features not yet supported by vite's
default compiler, esbuild
.
npm install --save-dev vite-plugin-typescript-transform
See the Options
interface and its inline documentation.
This plugin does not change or disable any of vite's
compiler/features/options. It only transpiles the code using the typescript
compiler and lets vite
move on with the transpiled code.
The new ECMAScript decorators are not supported by esbuild
(yet), but they are supported by typescript
since v5
(see the announcement). This example down-levels the new decorators into code that is usable in runtimes that do not yet support it.
import ts from 'typescript';
import { defineConfig } from 'vite';
import { vitePluginTypescriptTransform } from 'vite-plugin-typescript-transform';
export default defineConfig({
// ...your vite configuration
plugins: [
vitePluginTypescriptTransform({
enforce: 'pre',
filter: {
files: {
include: /\.ts$/,
},
},
tsconfig: {
override: {
target: ts.ScriptTarget.ES2021,
},
},
}),
],
});