vue-global-api is a utility package for Vue 3 that makes Composition API functions globally available within `<script setup>` contexts, removing the need for explicit imports of `ref`, `computed`, `watch`, and other common APIs from 'vue'. This aims to reduce boilerplate and streamline the development experience, aligning with the macro-like availability of `defineProps` and `defineEmits`. The current stable version is `0.4.1`, and it's maintained by Anthony Fu, a prominent Vue core team member. While Vue itself doesn't have a fixed release cycle for minor versions (typically 3-6 months), this package tends to follow its development. Key differentiators include its granular control over which APIs are global via sub-module imports (e.g., `vue-global-api/ref` or `vue-global-api/reactivity`), and its specific ESLint configuration to prevent 'no-undef' errors. It is designed for bundler-based Vue applications and offers an alternative to importing APIs from 'vue' in every single-file component.
npm install vue-global-apiVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates the core usage of `vue-global-api` by registering all common Composition APIs globally in `main.ts` and then using them directly in a Vue component without explicit imports. It also includes the necessary ESLint configuration.
Extend your ESLint configuration with `'vue-global-api'` (or specific sub-configs like `'vue-global-api/reactivity'`). Refer to the package's documentation for exact syntax.
Ensure the `import 'vue-global-api'` statement is placed early in your main entry file (e.g., `main.ts` or `main.js`), typically right after Vue's `createApp` import.
If using a CDN, avoid this package and instead use `Object.assign(window, Vue)` after loading the Vue global build. This package is specifically for module-based bundler environments.
Use the side-effect import syntax: `import 'vue-global-api'` or `import 'vue-global-api/ref'`.
Add `'vue-global-api'` to the `extends` array in your `.eslintrc.js` (or `.eslintrc.cjs`) configuration file. For example: `extends: ['plugin:vue/vue3-recommended', 'vue-global-api']`.
Ensure `import 'vue-global-api'` is present in your application's entry file (e.g., `main.ts`) and that it executes *before* any Vue components are initialized. Verify Vue 3 is correctly installed and configured.
Install the package using `npm install vue-global-api` or `yarn add vue-global-api`. Check `package.json` to confirm it's listed in `dependencies`.