{"id":22677,"library":"vite-plugin-glob","title":"vite-plugin-glob","description":"An experimental Vite plugin providing an enhanced glob import API with support for multiple patterns, ignore, custom queries, and selective default/named exports. Current version 0.3.2. It served as a design experiment that influenced Vite's built-in import.meta.glob, offering features like HMR on file changes and Vite alias support before they were integrated into core. Active development but note that Vite v3.0 has since ported some of its features, making this plugin primarily useful for experimentation or using specific options not yet in core. Key differentiator: unified API with options like eager, query, as, and import, allowing fine-grained control over globbed imports.","status":"maintenance","version":"0.3.2","language":"javascript","source_language":"en","source_url":"https://github.com/antfu/vite-plugin-glob","tags":["javascript","typescript"],"install":[{"cmd":"npm install vite-plugin-glob","lang":"bash","label":"npm"},{"cmd":"yarn add vite-plugin-glob","lang":"bash","label":"yarn"},{"cmd":"pnpm add vite-plugin-glob","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency; plugin only works within Vite's build pipeline.","package":"vite","optional":false}],"imports":[{"note":"ESM-only; CommonJS require not supported.","wrong":"const GlobPlugin = require('vite-plugin-glob')","symbol":"default","correct":"import GlobPlugin from 'vite-plugin-glob'"},{"note":"Use import.meta.importGlob to avoid conflict with Vite's built-in import.meta.glob unless setting takeover: true.","wrong":"const modules = import.meta.glob('./dir/*.js')","symbol":"import.meta.importGlob","correct":"const modules = import.meta.importGlob('./dir/*.js')"},{"note":"Type-only import is correct for TypeScript; value import will cause runtime error.","wrong":"import { Options } from 'vite-plugin-glob'","symbol":"type Options","correct":"import type { Options } from 'vite-plugin-glob'"}],"quickstart":{"code":"// vite.config.ts\nimport { defineConfig } from 'vite'\nimport GlobPlugin from 'vite-plugin-glob'\n\nexport default defineConfig({\n  plugins: [\n    GlobPlugin({\n      // Enable to have this plugin handle import.meta.glob instead of Vite\n      // takeover: true,\n    }),\n  ],\n})\n\n// In any module:\nconst modules = import.meta.importGlob('./*.ts', { eager: true })\nconsole.log(modules)\n","lang":"typescript","description":"Shows how to install the plugin in vite.config and use import.meta.importGlob with eager option to load all .ts files immediately."},"warnings":[{"fix":"Update usage: { export: 'default' } -> { import: 'default' }","message":"The export option has been renamed to import in v0.3.0.","severity":"breaking","affected_versions":"<=0.2.9"},{"fix":"Set restoreQueryExtension: true if you need query extension restoration.","message":"restoreQueryExtension option is disabled by default since v0.3.0, meaning file extensions may not be restored in queries.","severity":"gotcha","affected_versions":">=0.3.0"},{"fix":"Consider using Vite's native import.meta.glob with Vite >=3.0 if you don't need this plugin's specific options.","message":"The takeover feature may become unnecessary as Vite core incorporates similar features; check Vite version compatibility.","severity":"deprecated","affected_versions":"*"},{"fix":"Either enable takeover: true or use distinct patterns to avoid confusion.","message":"Using import.meta.importGlob with the same pattern as Vite's import.meta.glob may cause conflicts if takeover is not enabled.","severity":"gotcha","affected_versions":">=0.3.0"},{"fix":"Upgrade to v0.3.2 or later for improved HMR handling.","message":"HMR may not work correctly for newly created files in some scenarios; see issue #22.","severity":"gotcha","affected_versions":"<=0.3.1"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Run npm install -D vite-plugin-glob from project root.","cause":"Package not installed or installed incorrectly.","error":"ERR_MODULE_NOT_FOUND: Cannot find module 'vite-plugin-glob'"},{"fix":"Ensure your file is .mjs or set type: module in package.json, or use dynamic import().","cause":"Using ES module import in a CommonJS file.","error":"Cannot use import statement outside a module"},{"fix":"Add GlobPlugin() to vite.config plugins array and restart Vite dev server.","cause":"Missing plugin setup in vite.config or plugin not applied before usage.","error":"Uncaught (in promise) TypeError: import.meta.importGlob is not a function"},{"fix":"Use import type { Options } from 'vite-plugin-glob'.","cause":"Trying to import Options as a value instead of a type.","error":"No matching export in 'vite-plugin-glob' for import 'Options'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}