Menu

Post image 1
Post image 2
1 / 2
0

Unplugin Has Free Universal Build Plugins — Here's How to Use Them

DEV Community: rollup·Alex Spinov·3 days ago
#BSn7u5cL
#dev#unplugin#fullscreen#const#import#article
Reading 0:00
15s threshold

Writing a plugin for Vite, webpack, Rollup, Rspack, AND esbuild means 5 different APIs. Unplugin lets you write it once — it works everywhere. What Is Unplugin? Unplugin is a universal plugin system from the UnJS ecosystem. Write one plugin that runs on Vite, Rollup, webpack, Rspack, esbuild, and Rolldown. Quick Start npm install unplugin Enter fullscreen mode Exit fullscreen mode import { createUnplugin } from ' unplugin ' ; const myPlugin = createUnplugin (( options ) => ({ name : ' my-plugin ' , transformInclude ( id ) { return id . endsWith ( ' .ts ' ); }, transform ( code , id ) { return code . replace ( /__VERSION__/g , ' "1.0.0" ' ); }, buildStart () { console . log ( ' Build started! ' ); }, })); // Export for each bundler export const vite = myPlugin . vite ; export const webpack = myPlugin . webpack ; export const rollup = myPlugin . rollup ; export const rspack = myPlugin . rspack ; export const esbuild = myPlugin .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More