Bundler integration
When a bundler (Vite, Webpack, Rollup, β¦) owns your build, you still want the ttsc plugin pass to run. @ttsc/unplugin is the adapter β same plugin contract, embedded inside the bundler.
Install
npm install -D ttsc @typescript/native-preview @ttsc/unpluginVite
// vite.config.ts
import ttsc from "@ttsc/unplugin/vite";
import { defineConfig } from "vite";
export default defineConfig({
plugins: [ttsc()],
});Webpack
// webpack.config.mjs
import ttsc from "@ttsc/unplugin/webpack";
export default {
entry: "./src/index.ts",
plugins: [ttsc()],
};Rollup / Rolldown
import ttsc from "@ttsc/unplugin/rollup"; // or "@ttsc/unplugin/rolldown"
export default {
input: "src/index.ts",
output: { dir: "dist", format: "esm" },
plugins: [ttsc()],
};esbuild
import { build } from "esbuild";
import ttsc from "@ttsc/unplugin/esbuild";
await build({
entryPoints: ["src/index.ts"],
outdir: "dist",
bundle: true,
plugins: [ttsc()],
});Rspack
import ttsc from "@ttsc/unplugin/rspack";
export default { entry: "./src/index.ts", plugins: [ttsc()] };Next.js
// next.config.mjs
import withTtsc from "@ttsc/unplugin/next";
export default withTtsc({
/* your Next config */
});Farm
import ttsc from "@ttsc/unplugin/farm";
import { defineConfig } from "@farmfe/core";
export default defineConfig({ plugins: [ttsc()] });Bun
import ttsc from "@ttsc/unplugin/bun";
await Bun.build({
entrypoints: ["./src/index.ts"],
outdir: "./dist",
plugins: [ttsc()],
});Configuration
@ttsc/unplugin reads your existing tsconfig.json β same plugins, same configs (lint.config.ts, banner.config.ts, β¦). For most projects no adapter-specific options are needed.
If the bundler invokes from a different cwd, or you want a non-default tsconfig:
ttsc({
cwd: process.cwd(),
project: "tsconfig.build.json",
});When do I use this vs the ttsc CLI?
| Setup | Use |
|---|---|
| Pure Node library, no bundler | npx ttsc |
| Frontend with Vite / Webpack / Rspack | @ttsc/unplugin inside the bundler |
| Backend (e.g., NestJS) bundled with Webpack | @ttsc/unplugin |
| Both β monorepo with library + frontend | CLI for the library, @ttsc/unplugin for the frontend |
The plugin pass is identical either way. Diagnostics show up wherever the bundler surfaces them.
See also
- TTSC Β·
ttscCLI β the standalone path. - Plugins β what runs inside the bundler.
- Troubleshooting β bundler-specific gotchas.
Last updated on