Registry / web-framework / vue-global-api

vue-global-api

JSON →
library0.4.1jsnpmunverified

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-api
INSTALL
IMPORT
SIG · VUE-GLOBAL-API
V
vue-global-api
web-frameworkjavascriptv0.4.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Global Registration
import 'vue-global-api'
import { ref } from 'vue-global-api'
This is a side-effect import that globally registers all common Composition APIs. It must be imported in your main entry file (e.g., `main.ts`) before any Vue components are used. Do not try to import named exports from the root package.
Specific API Registration
import 'vue-global-api/ref'
const ref = require('vue-global-api/ref')
For fine-grained control, you can import individual APIs as side effects. This is primarily an ESM-only library, used in modern Vue setups (Vite, webpack with ESM support).
Collection Registration
import 'vue-global-api/reactivity'
import { watch } from 'vue-global-api/reactivity'
Collections like 'reactivity' (for `ref`, `computed`, `watch`) or 'lifecycle' (for `onMounted`, etc.) can also be imported as side effects. Like other imports from this package, they don't export values directly, but rather register them globally.

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.

/* main.ts */ import { createApp } from 'vue' import App from './App.vue' // Globally register all common Vue Composition APIs // This must be imported BEFORE any Vue components that use these globals import 'vue-global-api' createApp(App).mount('#app') /* App.vue */ <script setup lang="ts"> // No need to import ref, computed, watch, etc. // They are globally available thanks to 'vue-global-api' const counter = ref(0) const doubled = computed(() => counter.value * 2) watch(doubled, (v) => { console.log('Doubled value changed:', v) }) function increment() { counter.value++ } </script> <template> <div> <h1>Counter: {{ counter }}</h1> <h2>Doubled: {{ doubled }}</h2> <button @click="increment">Increment</button> </div> </template> <style scoped> /* Your styles here */ </style> /* .eslintrc.js (or .eslintrc.cjs) */ module.exports = { extends: [ 'eslint:recommended', 'plugin:vue/vue3-recommended', 'vue-global-api' // Extend the ESLint config for global APIs // Or for fine-grain control: // 'vue-global-api/reactivity' ] // ... other ESLint configurations }
Debug
Known issues
gotchaFailing to configure ESLint will result in 'no-undef' errors for globally exposed APIs.
fix
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.
affects: >=0.1.0
gotchaThe global registration import (`import 'vue-global-api'`) must occur *before* any Vue components are processed that utilize these global APIs.
fix
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.
affects: >=0.1.0
gotchaThis package is not designed for direct CDN usage. For browser environments without a bundler, the recommended approach is to manually assign Vue's global object to `window` (e.g., `Object.assign(window, Vue)`).
fix
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.
affects: >=0.1.0
gotchaDo not attempt to import named exports directly from `vue-global-api` or its submodules (e.g., `import { ref } from 'vue-global-api'`). The package works by side-effect global registration.
fix
Use the side-effect import syntax: `import 'vue-global-api'` or `import 'vue-global-api/ref'`.
affects: >=0.1.0
Errors
Common errors & fixes
ESLint: 'ref' is not defined. (no-undef)
ESLint is not aware that `ref` (or other global APIs) are globally available through `vue-global-api`.
fix
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']`.
TypeError: ref is not a function
The `vue-global-api` package was either not imported, or it was imported *after* a component that attempted to use a global API.
fix
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.
Module not found: Error: Can't resolve 'vue-global-api'
The `vue-global-api` package is not installed or incorrectly referenced in `package.json`.
fix
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`.
Upgrade
Version history
0.4.1latest on npm
Audit
Dependencies
vuerequiredProvides the Composition API functions that this package makes global.
Agent activity
7 hits · last 30 days
node
6
OpenAI (training)
1
Resources
vue-global-api — npm install vue-global-api · libregistry