Vue Macros Unplugin

2.14.5 · active · verified Sun Apr 19

unplugin-vue-macros is a comprehensive collection of macros and syntax sugar designed to enhance the developer experience in Vue.js projects. It operates as an `unplugin`, providing broad compatibility across various bundlers like Vite, Webpack, Rollup, and esbuild. This library introduces experimental and advanced features that may not yet be officially adopted by Vue's core, simplifying common patterns and offering more expressive ways to write components. The current stable version, as per the recent changelog, is v3.1.2. The project maintains an active release cadence, frequently pushing minor bug fixes and features, with significant breaking changes typically occurring in major version bumps. Key differentiators include its modular design, allowing developers to pick and choose specific macros, its seamless integration via the `unplugin` system, and robust TypeScript and Volar support.

Common errors

Warnings

Install

Imports

Quickstart

This Vite configuration demonstrates how to integrate `unplugin-vue-macros` into a Vue 3 TypeScript project, enabling various macros and optionally setting up auto-imports.

import { defineConfig } from 'vite';
import Vue from '@vitejs/plugin-vue';
import VueMacros from 'unplugin-vue-macros/vite';
import AutoImport from 'unplugin-auto-import/vite';

export default defineConfig({
  plugins: [
    VueMacros({
      // The `plugins` option is essential for Vue Macros to correctly process Vue SFCs.
      // It should include the `@vitejs/plugin-vue` instance.
      plugins: {
        vue: Vue(),
        // vueJsx: VueJsx(), // Uncomment if you are using JSX
      },
      // You can also enable/disable specific macros here
      defineOptions: true,
      defineModels: true,
    }),
    // Optional: AutoImport can be used to automatically import Vue Macros APIs
    AutoImport({
      imports: ['vue', '@vue/composition-api'],
      dts: './auto-imports.d.ts',
      macros: {
        // Enable definePropsRefs if you use it globally or want auto-import
        // definePropsRefs: true,
      },
      eslintrc: {
        enabled: true,
        filepath: './.eslintrc-auto-import.json',
      },
    }),
  ],
});

view raw JSON →