Building universal JS/TS plugins with unplugin

building-universal-js/ts-plugins-with-unplugin

I started building my open source projects for the community some time ago already. It always gave me a lot of joy when I noticed that the amount of GitHub Stars was growing each day. First, I was building project with Nest.js, next with Nuxt.js and only recently, I have found that developing tools with Vite is even better because you can reach even bigger audience. And just few days, when I started working on my new tool contentine (that I will publish quite soon btw) I found out the project called unplugin.

Make sure to check it out here

unplugin is a short from Unified plugin system for build tools. In simple words, it means that you can develop a plugin that has an unified interface that will work with webpack, rollup, vite, and esbuild. Vite was a game changer because it allowed me to to build a tool that was working for React, Vue, and Svelte, and now, with unplugin, you can target almost all audiences with a single plugin tool.

Usage

It is fairly simple and explained quite well in the README.md but I will copy it here anyway:

import { createUnplugin } from 'unplugin'

export const unplugin = createUnplugin((options: UserOptions) => {
  return {
    name: 'unplugin-prefixed-name',
    // webpack's id filter is outside of loader logic,
    // an additional hook is needed for better perf on webpack
    transformInclude (id) {
      return id.endsWith('.vue')
    },
    // just like rollup transform
    transform (code) {
      return code.replace(/