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.
npm install unplugin-vue-macrosVerified import paths — ran on the pinned version, not inferred.
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.
Upgrade your project to Vue 3 (>=3.2.25), Webpack 5+, and Node.js >=20.19.0. Refer to the official migration guide from v2 to v3 for detailed steps.
Review your component emit declarations; adapt to standard Vue 3.3+ `defineEmits` usage if `shortEmits` was previously relied upon.
Ensure your development and build environments use Node.js version 20.19.0 or higher.
Always import the plugin from its specific bundler entry point in your `vite.config.ts`, `webpack.config.js`, etc., for example: `import VueMacros from 'unplugin-vue-macros/vite'`.
Add `"unplugin-vue-macros/macros-global"` to the `compilerOptions.types` array in your `tsconfig.json` or add a triple-slash directive to a `.d.ts` file.
Change the import statement to include the bundler, e.g., `import VueMacros from 'unplugin-vue-macros/vite'` for Vite.
Ensure `unplugin-vue-macros` is correctly configured in your bundler and that TypeScript type references (`tsconfig.json` `types` array or `/// <reference>`) are set up for `macros-global`.
Update your `defineEmits` syntax to the standard Vue 3.3+ approach, or verify if an alternative macro is available and enabled in your configuration.
Upgrade your Node.js version to 20.19.0 or higher.