@ttsc/unplugin
v0.15.1
Published
Bundler adapters for ttsc plugins.
Maintainers
Readme
@ttsc/unplugin

Bundler adapter for ttsc plugins.
Use it when Vite, Rollup, esbuild, Webpack, Rspack, Next.js, Farm, or Bun owns the build but the project still needs ttsc plugins.
Setup
Install ttsc and TypeScript-Go first. Then install the bundler adapter:
npm install -D ttsc @typescript/native-preview
npm install -D @ttsc/unpluginChoose your bundler and add the adapter.
Vite
// vite.config.ts
import ttsc from "@ttsc/unplugin/vite";
import { defineConfig } from "vite";
export default defineConfig({
plugins: [ttsc()],
});Rollup
// rollup.config.ts
import ttsc from "@ttsc/unplugin/rollup";
export default {
input: "src/index.ts",
output: {
dir: "dist",
format: "esm",
},
plugins: [ttsc()],
};Rolldown
// rolldown.config.ts
import ttsc from "@ttsc/unplugin/rolldown";
export default {
input: "src/index.ts",
output: {
dir: "dist",
format: "esm",
},
plugins: [ttsc()],
};esbuild
// esbuild.config.ts
import { build } from "esbuild";
import ttsc from "@ttsc/unplugin/esbuild";
await build({
entryPoints: ["src/index.ts"],
outdir: "dist",
bundle: true,
plugins: [ttsc()],
});Webpack
// webpack.config.mjs
import ttsc from "@ttsc/unplugin/webpack";
export default {
entry: "./src/index.ts",
output: {
path: new URL("./dist", import.meta.url).pathname,
},
plugins: [ttsc()],
};Rspack
// rspack.config.mjs
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";
/** @type {import("next").NextConfig} */
const nextConfig = {
reactStrictMode: true,
};
export default withTtsc(nextConfig);Farm
// farm.config.ts
import ttsc from "@ttsc/unplugin/farm";
import { defineConfig } from "@farmfe/core";
export default defineConfig({
plugins: [ttsc()],
});Bun
// build.ts
import ttsc from "@ttsc/unplugin/bun";
await Bun.build({
entrypoints: ["src/index.ts"],
outdir: "dist",
plugins: [ttsc()],
});Configuration
By default, @ttsc/unplugin finds the nearest tsconfig.json from the file being transformed and uses that project's plugin settings, including directly installed plugin packages.
If that is already the config you want, ttsc() is enough.
Project Selection
Use project when the bundler should read a different config file:
import ttsc from "@ttsc/unplugin/vite";
export default {
plugins: [
ttsc({
project: "tsconfig.bundle.json",
}),
],
};The project path is resolved from process.cwd().
Inline Compiler Options
Use compilerOptions when the bundler needs a small override without another config file:
import ttsc from "@ttsc/unplugin/vite";
export default {
plugins: [
ttsc({
compilerOptions: {
plugins: [
{
transform: "@ttsc/lint",
rules: { noVar: "error" },
},
{
transform: "typia/lib/transform",
finite: true,
},
],
},
}),
],
};compilerOptions is layered on top of the selected project config. Existing settings stay in place, and only the fields you pass here are changed for the bundler build.
Plugin Overrides
Use the top-level plugins option inside ttsc(...) when the bundler should use a different plugin list from tsconfig.json:
import ttsc from "@ttsc/unplugin/vite";
export default {
plugins: [
ttsc({
plugins: [
{ transform: "@ttsc/lint", rules: { noVar: "error" } },
{ transform: "typia/lib/transform" },
],
}),
],
};Explicit adapter options override the plugin list read from the selected project config.
Set plugins: false to run the adapter without loading project plugins.
Next.js Options
Pass adapter options as the second argument:
// next.config.mjs
import withTtsc from "@ttsc/unplugin/next";
/** @type {import("next").NextConfig} */
const nextConfig = {
reactStrictMode: true,
};
export default withTtsc(nextConfig, {
project: "tsconfig.bundle.json",
});Adapter Entrypoints
Import the entrypoint that matches your bundler:
import ttsc from "@ttsc/unplugin/vite";Supported entrypoints are:
@ttsc/unplugin/vite@ttsc/unplugin/esbuild@ttsc/unplugin/rollup@ttsc/unplugin/rolldown@ttsc/unplugin/webpack@ttsc/unplugin/rspack@ttsc/unplugin/farm@ttsc/unplugin/next@ttsc/unplugin/bun
Each entrypoint supports ESM import and CJS require. In CommonJS configs, read the default export from require("@ttsc/unplugin/vite").default.
Options
import type { TtscUnpluginOptions } from "@ttsc/unplugin";
const options: TtscUnpluginOptions = {
project: "tsconfig.json",
compilerOptions: {
baseUrl: ".",
},
plugins: false,
};project: path to thetsconfig.jsonused by the bundler.compilerOptions: temporary override layered on the selected project config.plugins: directttscplugin list override, orfalseto disable plugins.
Sponsors
Thanks for your support.
Your donation encourages ttsc development.
References
Inspired by @ryoppippi/unplugin-typia.
