Vite TypeScript Transform Plugin

1.3.1 · active · verified Sun Apr 19

vite-plugin-typescript-transform is a Vite plugin designed to integrate the full TypeScript compiler into the Vite build transform phase. Its primary purpose is to enable advanced TypeScript features, such as the new ECMAScript decorators, that Vite's default transpiler, esbuild, might not yet support. The plugin operates by transpiling code using the TypeScript compiler before esbuild processes it, allowing developers to leverage the latest TypeScript syntax without waiting for esbuild updates. Currently at version 1.3.1, the package demonstrates active maintenance with several releases in the past year addressing bug fixes and feature enhancements, such as improved tsconfig parsing. It functions as an augmentation to Vite's pipeline, rather than a replacement, and requires careful configuration of plugin order to ensure correct operation.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to configure the plugin in `vite.config.ts` to apply TypeScript transformation, specifically highlighting the use of `enforce: 'pre'` and `tsconfig.override` for features like ECMAScript decorators.

import ts from 'typescript';
import { defineConfig } from 'vite';
import { vitePluginTypescriptTransform } from 'vite-plugin-typescript-transform';

export default defineConfig({
  plugins: [
    vitePluginTypescriptTransform({
      enforce: 'pre',
      filter: {
        files: {
          include: /\.ts$/,
        },
      },
      tsconfig: {
        override: {
          target: ts.ScriptTarget.ES2021,
          // Enable new ECMAScript decorators support if needed
          // 'experimentalDecorators' is for legacy decorators
          // 'useDefineForClassFields' often needed for new decorators
          // For new decorators, ensure TypeScript version is >=5.0
        },
      },
    }),
  ],
  // ... other vite configuration
});

view raw JSON →