All Projects → unjs → unplugin

unjs / unplugin

Licence: MIT License
Unified plugin system for Vite, Rollup, Webpack, and more

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to unplugin

vue-frag-plugin
Webpack/Rollup/Vite plugin to add multiple root-node support to Vue 2 SFCs
Stars: ✭ 37 (-96.29%)
Mutual labels:  rollup, vite
electron-template
Electron multiwindow mode template
Stars: ✭ 65 (-93.49%)
Mutual labels:  rollup, vite
Workflow
一个工作流平台
Stars: ✭ 1,888 (+89.18%)
Mutual labels:  rollup, vite
electron-vue-next
A starter template for using vue-next with the electron.
Stars: ✭ 189 (-81.06%)
Mutual labels:  rollup, vite
howdyjs
一个包含Javascript插件、Vue3组件、Vue3指令的工具库
Stars: ✭ 77 (-92.28%)
Mutual labels:  rollup, vite
unplugin-icons
🤹 Access thousands of icons as components on-demand universally.
Stars: ✭ 2,064 (+106.81%)
Mutual labels:  vite, unplugin
vitext
The Next.js like React framework for better User & Developer experience!
Stars: ✭ 376 (-62.32%)
Mutual labels:  rollup, vite
aria-vue
Testing tools for Vue components
Stars: ✭ 21 (-97.9%)
Mutual labels:  rollup, vite
unplugin-vue
✨ Transform Vue 3 SFC to JavaScript. Supports Vite, esbuild, Rollup and Webpack.
Stars: ✭ 38 (-96.19%)
Mutual labels:  rollup, unplugin
react-antd-low-code
简易版 react 低代码平台
Stars: ✭ 45 (-95.49%)
Mutual labels:  vite
optimism
The Optimism monorepo
Stars: ✭ 884 (-11.42%)
Mutual labels:  rollup
monoreact
📦 React workspaces implementation
Stars: ✭ 13 (-98.7%)
Mutual labels:  rollup
vite-react-ts-tailwind-firebase-starter
Starter using Vite + React + TypeScript + Tailwind CSS. And already set up Firebase(v9), Prettier and ESLint.
Stars: ✭ 108 (-89.18%)
Mutual labels:  vite
vue-3-stackter
A Vue3 starter project setup with Vite, Vue-meta, Router, Vuex, Eslint, Prettier, Tailwind CSS, and some custom preferences. Also, there is a TypeScript branch of this same setup.
Stars: ✭ 93 (-90.68%)
Mutual labels:  vite
vite-plugin-env-compatible
Environment Variables Compatible for vite(with vue-cli, create-react-app and so on)
Stars: ✭ 35 (-96.49%)
Mutual labels:  vite
vitawind
Install and Setting Tailwindcss automatically for Vite
Stars: ✭ 46 (-95.39%)
Mutual labels:  vite
vue3-realworld-example-app
Explore the charm of Vue composition API! Vite?
Stars: ✭ 364 (-63.53%)
Mutual labels:  vite
swappy-one
swappy.one
Stars: ✭ 24 (-97.6%)
Mutual labels:  vite
postcss-font-grabber
A postcss plugin, it grabs remote font files and update your CSS, just like that.
Stars: ✭ 26 (-97.39%)
Mutual labels:  rollup
theme-generator
CSS Color Theme Generator based on Numl.Design theme generator & HSLuv color space 🌈
Stars: ✭ 17 (-98.3%)
Mutual labels:  vite

unplugin

NPM version

Unified plugin system for build tools.

Currently supports:

Hooks

unplugin extends the excellent Rollup plugin API as the unified plugin interface and provides a compatible layer base on the build tools used with.

Supported
Hook Rollup Vite Webpack 4 Webpack 5 esbuild
buildStart
buildEnd
transformInclude1
transform 3
enforce 2 2
resolveId
load 3
  1. Webpack's id filter is outside of loader logic; an additional hook is needed for better perf on Webpack. In Rollup and Vite, this hook has been polyfilled to match the behaviors. See for following usage examples.
  2. Rollup and esbuild do not support using enforce to control the order of plugins. Users need to maintain the order manually.
  3. Although esbuild can handle both JavaScript and CSS and many other file formats, you can only return JavaScript in load and transform results.

Usage

import { createUnplugin } from 'unplugin'

export const unplugin = createUnplugin((options: UserOptions) => {
  return {
    name: 'my-first-unplugin',
    // 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(/<template>/, `<template><div>Injected</div>`)
    },
    // more hooks coming
  }
})

export const vitePlugin = unplugin.vite
export const rollupPlugin = unplugin.rollup
export const webpackPlugin = unplugin.webpack
export const esbuildPlugin = unplugin.esbuild

Plugin Installation

Vite
// vite.config.ts
import MyUnplugin from './my-unplugin'

export default {
  plugins: [
    MyUnplugin.vite({ /* options */ })
  ]
}
Rollup
// rollup.config.js
import MyUnplugin from './my-unplugin'

export default {
  plugins: [
    MyUnplugin.rollup({ /* options */ })
  ]
}
Webpack
// webpack.config.js
module.exports = {
  plugins: [
    require('./my-unplugin').webpack({ /* options */ })
  ]
}
esbuild
// esbuild.config.js
import { build } from 'esbuild'

build({
  plugins: [
    require('./my-unplugin').esbuild({ /* options */ })
  ]
})

Framework-specific Logic

While unplugin provides compatible layers for some hooks, the functionality of it is limited to the common subset of the build's plugins capability. For more advanced framework-specific usages, unplugin provides an escape hatch for that.

export const unplugin = createUnplugin((options: UserOptions, meta) => {

  console.log(meta.framework) // 'vite' | 'rollup' | 'webpack' | 'esbuild'

  return {
    // common unplugin hooks
    name: 'my-first-unplugin',
    transformInclude (id) { /* ... */ },
    transform (code) { /* ... */  },
    
    // framework specific hooks
    vite: {
      // Vite config
      configureServer(server) {
        // configure Vite server
      }
    },
    rollup: {
      // Rollup config
    },
    webpack(compiler) {
      // configure Webpack compiler
    },
    esbuild: {
      // change the filter of onResolve and onLoad
      onResolveFilter?: RegExp
      onLoadFilter?: RegExp
      // or you can completely replace the setup logic
      setup?: EsbuildPlugin['setup']
    }
  }
})

Starter Templates

Examples

License

MIT License © 2021 Nuxt Contrib

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].