unplugin for typia
npm install @kennethwkz/unplugin-typiaunplugin for Typia



Typia is fantastic, but it is hard to setup, even for frontend development.
If you use some bundlers for frontend like Vite, it is even harder to setup.
This unplugin aims to make it easier to use Typia in your projects.
First, install unplugin-typia:
``bash`npm
npm install -D @kennethwkz/unplugin-typia
Then, install typia:
`bashinstall typia! (nypm detects your PM ✨)
npx nypm add typia
More details about setting up Typia can be found in the Typia Docs.
Then, add the unplugin to your favorite bundler:
Vite
`ts
// vite.config.ts
import UnpluginTypia from '@kennethwkz/unplugin-typia/vite';export default defineConfig({
plugins: [
UnpluginTypia({ tsconfig: './tsconfig.app.json' / options / }), // should be placed before other plugins like
react, svetle, etc.
],
});
`> When using typia with types imported from non-relative paths like tsconfig
compilerOptions.paths or relative to
> tsconfig compilerOptions.baseUrl, they must be defined in vite.config.ts under resolve.alias
> in order to be resolved, according to vite's resolution mechanism.Examples:
examples/vite-react
- examples/vite-hono
- examples/sveltekit
esbuild
`ts
// esbuild.config.js
import UnpluginTypia from '@kennethwkz/unplugin-typia/esbuild';export default {
plugins: [
UnpluginTypia({ / options / }),
],
};
`Examples:
tests/rollup.spec.ts
Next.js
`js
// next.config.mjs
import unTypiaNext from 'unplugin-typia/next';/* @type {import('next').NextConfig} /
const nextConfig = { / your next.js config /};
/* @type {import("unplugin-typia").Options} /
const unpluginTypiaOptions = { / your unplugin-typia options / };
export default unTypiaNext(nextConfig, unpluginTypiaOptions);
// you can omit the unplugin-typia options when you don't need to customize it
// export default unTypiaNext(nextConfig);
`Examples:
examples/nextjs
Bun.build
$3
`ts
// build.ts
import UnpluginTypia from '@kennethwkz/unplugin-typia/bun';await Bun.build({
entrypoints: ['./index.ts'],
outdir: './out',
plugins: [
UnpluginTypia({ / your options /})
]
});
`For building the script:
`sh
bun run ./build.ts
node ./out/index.js
`Check the Plugins – Bundler | Bun Docs for more details.
$3
`ts
// preload.ts
import { plugin } from 'bun';
import UnpluginTypia from '@kennethwkz/unplugin-typia/bun';plugin(UnpluginTypia({ / your options /}));
``toml
bun.toml
preload = "preload.ts"[test]
preload = "preload.ts"
`For running the script:
`sh
bun run ./index.ts
`Check the Plugins – Runtime | Bun Docs for more details.
Rollup
`ts
// rollup.config.js
import UnpluginTypia from '@kennethwkz/unplugin-typia/rollup';export default {
plugins: [
UnpluginTypia({ / options / }),
],
};
`Examples:
tests/rollup.spec.ts
Webpack
`js
// webpack.config.jsconst { default: UnpluginTypia } = require('@kennethwkz/unplugin-typia/webpack');
module.exports = {
plugins: [
UnpluginTypia({ / options / }),
],
};
`
examples/.Supported File Extensions
-
.ts
- .tsx
- .mts
- .mtsx
- .svelte (only script tag with lang="ts")Development
This repository is a monorepo managed by Bun.
`sh
bun i --frozen-lockfile
``This project started as an unofficial integration of Typia for bundlers.
Now, this plugin is one of the official integrations of Typia and is sponsored by @samchon (the creator of Typia).