npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@ryoppippi/unplugin-typia

v1.0.7

Published

unplugin for typia

Downloads

3,242

Readme

unplugin-typia

unplugin for Typia

npm version npm downloads

JSR JSR

Why

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.

Install

First, install unplugin-typia:

# jsr(recommended)
npx jsr add -D @ryoppippi/unplugin-typia

# npm
npm install -D @ryoppippi/unplugin-typia

Then, install typia:

# install typia! (nypm detects your PM ✨)
npx nypm add typia

# setup typia!
npx typia setup
# pnpm dlx typia setup
# yarn dlx typia setup

# after installing typia, run prepare script
npm run prepare

More details about setting up Typia can be found in the Typia Docs.

Then, add the unplugin to your favorite bundler:

// vite.config.ts
import UnpluginTypia from '@ryoppippi/unplugin-typia/vite';

export default defineConfig({
	plugins: [
		UnpluginTypia({ /* 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:

// esbuild.config.js
import UnpluginTypia from '@ryoppippi/unplugin-typia/esbuild';

export default {
	plugins: [
		UnpluginTypia({ /* options */ }),
	],
};

Examples:

// 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:

Example 1: Using for building script

// build.ts
import UnpluginTypia from '@ryoppippi/unplugin-typia/bun';

await Bun.build({
	entrypoints: ['./index.ts'],
	outdir: './out',
	plugins: [
		UnpluginTypia({ /* your options */})
	]
});

For building the script:

bun run ./build.ts
node ./out/index.js

Check the Plugins – Bundler | Bun Docs for more details.

Example 2: Using for running script

// preload.ts
import { plugin } from 'bun';
import UnpluginTypia from '@ryoppippi/unplugin-typia/bun';

plugin(UnpluginTypia({ /* your options */}));
# bun.toml
preload = "preload.ts"

[test]
preload = "preload.ts"

For running the script:

bun run ./index.ts

Check the Plugins – Runtime | Bun Docs for more details.

// rollup.config.js
import UnpluginTypia from '@ryoppippi/unplugin-typia/rollup';

export default {
	plugins: [
		UnpluginTypia({ /* options */ }),
	],
};

Examples:

⚠️ Note: Currently, this plugin works only with 'esm' target.

If you want to use 'cjs' target on Node < 20.17.0 , please use with jiti. If you want to use 'cjs' target on Node >= 20.17.0, please use with require and enable --experimental-require-modules flag. If you want to use 'esm' target, don't worry! You can use this plugin without any additional setup.

npm install jiti
// webpack.config.js

// if you use Node < 20.17.0
const jiti = require('jiti')(__filename);
const { default: UnpluginTypia } = jiti('@ryoppippi/unplugin-typia/webpack');

// if you use Node >= 20.17.0
// const { default: UnpluginTypia } = require("@ryoppippi/unplugin-typia/webpack");

module.exports = {
	plugins: [
		UnpluginTypia({ /* options */ }),
	],
};

More integration guides can be found in the JSR Doc

You can find examples in the examples/.

Supported File Extensions

  • .ts
  • .tsx
  • .mts
  • .mtsx
  • .svelte (only script tag with lang="ts")

Development

This repository is a monorepo managed by Bun.

bun i --frozen-lockfile

Acknowledgements

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).

LICENSE

MIT

analytics