Vue Macros is a collection of experimental and advanced compiler macros and syntax sugar designed to significantly enhance the development experience for Vue.js Single File Components (SFCs). It serves as a playground for new language features and proposals that extend Vue's capabilities beyond its official API, often simplifying boilerplate and improving reactivity patterns. The current stable version is 3.1.2, with an active release cadence reflecting ongoing development and frequent updates. Key differentiators include its modular nature, allowing developers to selectively enable specific macros, and its integration as an `unplugin`, providing broad compatibility across various build tools like Vite, Rollup, Webpack, and Nuxt. It brings features like `defineOptions`, `defineModels`, and `definePropsRefs` that streamline component definition and data flow, offering type safety and improved developer ergonomics.
npm install vue-macrosVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to configure Vue Macros in a Vite project and use the `defineOptions` macro in a Vue 3 SFC to set component options directly within `<script setup>`.
Upgrade Node.js to version >=20.19.0. Migrate Vue.js projects to Vue 3.x and ensure your build tool (e.g., Webpack) is on a compatible version (Webpack 5+).
Update your Node.js environment to version 20.19.0 or higher. Consider using a Node Version Manager (nvm) for easy switching.
For Vue 3.3+, use the officially provided `defineEmits` features or check Vue Macros documentation for any alternative configuration to re-enable or replace `shortEmits` functionality.
Update import paths (e.g., `unplugin-vue-macros/vite` instead of `vue-macros` directly if used as a plugin) and ensure your project uses ESM-compatible bundling. Review the migration guide for specific package name changes.
Ensure your `tsconfig.json` includes `"types": ["unplugin-vue-macros/macros-global"]` and your Volar/Vue Language Features (Volar) extension in VSCode is updated. For ESLint, ensure `eslint-plugin-vue` is up-to-date and configured for compiler macros.
Ensure `unplugin-vue-macros` is installed as a development dependency: `npm install -D unplugin-vue-macros` or `yarn add -D unplugin-vue-macros`. Verify the import path in your build configuration matches your bundler (e.g., `unplugin-vue-macros/vite` for Vite).
Add `"unplugin-vue-macros/macros-global"` to the `types` array in your `tsconfig.json`. For ESLint, ensure `eslint-plugin-vue` is updated to at least v8 and configure your `.eslintrc` to recognize `vue/setup-compiler-macros` if still relevant for older setups.
Relocate the macro call (e.g., `defineModels`, `defineOptions`) into a `<script setup>` block in your Single File Component. These are compiler macros and are not intended for use in regular `<script>` blocks or JavaScript/TypeScript files.