{"_id":"@brillout/vite-plugin-glob","name":"@brillout/vite-plugin-glob","dist-tags":{"latest":"0.2.5"},"versions":{"0.2.5":{"name":"@brillout/vite-plugin-glob","version":"0.2.5","packageManager":"pnpm@6.32.3","description":"The design experiment for import.meta.glob from Vite","homepage":"https://github.com/antfu/vite-plugin-glob#readme","bugs":{"url":"https://github.com/antfu/vite-plugin-glob/issues"},"publishConfig":{"access":"public"},"license":"MIT","author":{"name":"Anthony Fu","email":"anthonyfu117@hotmail.com"},"repository":{"type":"git","url":"git+https://github.com/antfu/vite-plugin-glob.git"},"funding":"https://github.com/sponsors/antfu","main":"./dist/index.cjs","module":"./dist/index.mjs","types":"./dist/index.d.ts","exports":{".":{"require":"./dist/index.cjs","import":"./dist/index.mjs","types":"./dist/index.d.ts"},"./client":{"types":"./client.d.ts"},"./takeover":{"types":"./takeover.d.ts"}},"sideEffects":false,"scripts":{"build":"rimraf dist && unbuild","dev":"unbuild --stub","lint":"eslint .","play":"vite playground","prepublishOnly":"nr build","release":"bumpp --commit --push --tag && pnpm publish","start":"esno src/index.ts","test":"vitest","typecheck":"tsc --noEmit"},"dependencies":{"acorn":"^8.7.0","fast-glob":"^3.2.11","magic-string":"^0.26.1","micromatch":"^4.0.5","ufo":"^0.8.1"},"devDependencies":{"@antfu/eslint-config":"^0.19.1","@antfu/ni":"^0.14.0","@babel/types":"^7.17.0","@types/estree":"^0.0.51","@types/micromatch":"^4.0.2","@types/node":"^17.0.23","bumpp":"^7.1.1","c8":"^7.11.0","eslint":"^8.12.0","esno":"^0.14.1","jiti":"^1.13.0","pnpm":"^6.32.3","rimraf":"^3.0.2","rollup":"^2.70.1","typescript":"^4.6.3","unbuild":"^0.7.2","vite":"^2.8.6","vitest":"^0.8.0"},"gitHead":"63515ec06dcef21d28eb776b2ae8ab5d34eb1829","_id":"@brillout/vite-plugin-glob@0.2.5","_nodeVersion":"16.14.0","_npmVersion":"8.3.1","dist":{"integrity":"sha512-gGxgkjs64UbzO42Dy0SLyHSIvvW6E50Iw5vnz3cf/ex3u1elLb+8B+NsguKhmBt/yj8lKm4kcVNiefoKpbDI7A==","shasum":"92d4ca2036bc360798f3e96866c8132d997e43b8","tarball":"https://registry.npmjs.org/@brillout/vite-plugin-glob/-/vite-plugin-glob-0.2.5.tgz","fileCount":10,"unpackedSize":37388,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDZPo4qvtoccx0p6cpNXEmsMI1K44oqrimTjv1GWBdG2gIgMz4srWMnTCPc+SD14emqIzsN+AlsB4tU2HdgTU44UhE="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJiTbmaACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmoa+Q/+JPK4MZr5MR2Ws7MWlK52oJIAsJY+oA0yoESUlEb4tD2pU95d\r\nrma7QD0qZ7/Rp7YpiTBlY1xKSYVvH5CgpzqkUmrRZ6plc2dIVddKjwj5Ba+W\r\nP+T4MGznrBKgcBRdgzQg6ZBEJxKcZpKw6keouB/vsRldig0LgOKeWA7UzQ33\r\nVWZZm2BaIIRlTj8WroJMllJSUF65w9P4sILuG5rE0wEcdNTEKGKX2SBUIZLf\r\nn/oze3y7qglThSF6hQK4W/76yktDewucuxhbOR68YI52WSMzhVsy32ZTUVFI\r\nc2Hw9i0ISlBeEJGejpTIPAadF6rexzvQscZVFsxcUGTxhQeSUnHt2DJs89Mx\r\nk/W1BUgxuBYPo0TIP2wiMoPuXw0NpDpSmi5feI0lNyQuuR2UJpX+l5upahpQ\r\nVIvF8KFa+PLS1O6zGEpQuLjL6vh4LAzx48lSSy+OD3PDV1zzt5VQXvSRPOcU\r\nCYp6ZZ4b79atl3HRMQygUYL55jdN/J8gB+pmwJ5bFTvHkSsED5s7xIkpKNri\r\n6hy/DLq9uqr/jW9f9YPZrmZJdveWRuWCJLMxbq+DZN0zJn8YX5M764TmTmUl\r\nxjnjPQotXnBhxQTdyDuQZHgfOZpXlMGw1Bv/n6Vg9Idrz6jET04TO2Ya95oi\r\nXuEalzpQsfxivpF20hfZPNyQ9A4qFn8C6O4=\r\n=Y0TW\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"brillout","email":"npm@brillout.com"},"directories":{},"maintainers":[{"name":"brillout","email":"npm@brillout.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/vite-plugin-glob_0.2.5_1649260954763_0.30609202689209547"},"_hasShrinkwrap":false}},"time":{"created":"2022-04-06T16:02:34.679Z","0.2.5":"2022-04-06T16:02:34.922Z","modified":"2022-04-06T16:02:35.055Z"},"maintainers":[{"name":"brillout","email":"npm@brillout.com"}],"description":"The design experiment for import.meta.glob from Vite","homepage":"https://github.com/antfu/vite-plugin-glob#readme","repository":{"type":"git","url":"git+https://github.com/antfu/vite-plugin-glob.git"},"author":{"name":"Anthony Fu","email":"anthonyfu117@hotmail.com"},"bugs":{"url":"https://github.com/antfu/vite-plugin-glob/issues"},"license":"MIT","readme":"# vite-plugin-glob\n\n[![NPM version](https://img.shields.io/npm/v/vite-plugin-glob?color=a1b858&label=)](https://www.npmjs.com/package/vite-plugin-glob)\n\nThe design experiment for [`import.meta.glob` from Vite](https://vitejs.dev/guide/features.html#glob-import).\n\n## Motivations\n\nThere are quite some scenarios that `import.meta.glob` wasn't considered when it's been implemented at the beginning. So we received quite a few PRs to improve it.\n\nHowever, some design considerations might conflict with each other. For example, [`#2495 support ignore option for glob import`](https://github.com/vitejs/vite/pull/2495) supports the ignore glob as a second argument, while in [`#6953 import.meta.glob support ?raw`](https://github.com/vitejs/vite/pull/6953) we uses the second argument to specify glob query (and later been changed to `{ as }` via [`#7215 deprecate { assert: { type: raw }} in favor of { as: raw }`](https://github.com/vitejs/vite/pull/7215)).\n\nThere are several other PRs that touches it's design as well:\n\n- [`#7209 support custom modifiers for glob imports`](https://github.com/vitejs/vite/pull/7209)\n- [`#7482 add ignore option to import.meta.glob`](https://github.com/vitejs/vite/pull/7482)\n\nWith these two TC39 proposals ([`import-reflection`](https://github.com/tc39/proposal-import-reflection) and [`import-assertions`](https://github.com/tc39/proposal-import-assertions)) not settled yet, combining with different needs and design tradeoffs in each PR, making the good API design for `import.meta.glob` directly in Vite core becoming harder and more and more complex than it could be (with the cautions to not break existing usages).\n\nOn top of that, in Vite we are having multiple macros for different options:\n\n- `import.meta.glob`\n- `import.meta.globEager`\n- `import.meta.globEagerDefault` (undocumented)\n\nThat results in a quite large API surface to maintain and make the future extension harder. For example, if we want `import.meta.globNamed` we might also need to add `import.meta.globEagerNamed`, making the counts to 5.\n\nThus I propose to experiment with the `import.meta.glob` as an external plugin so we could introduce breaking change more easier and ships the implementation much faster (in Vite it takes days for a change to be meraged, and weeks to months for it to be landed in stable release). And when we feel the new design is able to cover most of the use cases, then we could embed it into Vite core as a one-time breaking change in v3.0.\n\n## Features\n\n- Globing for multiple patterns\n- Globing ignore\n- HMR on file modification / addition / deletion\n- Ability to provide custom queries\n- Ability to only import default / named export\n- An unified API for different options\n- Vite alias\n- (Optional) Takeover Vite's `import.meta.glob`\n\n## Experiments\n\nThe following features are in experiments, feedbacks are greatly welcome!\n\n- [Restore file extension when query is specified](https://github.com/antfu/vite-plugin-glob/pull/10)\n\n## Install\n\n```bash\nnpm i -D vite-plugin-glob\n```\n\n```ts\n// vite.config.ts\nimport { defineConfig } from 'vite'\nimport GlobPlugin from 'vite-plugin-glob'\n\nexport default defineConfig({\n  plugins: [\n    GlobPlugin({\n      // enable to let this plugin interpret `import.meta.glob`\n      // takeover: true,\n    }),\n  ],\n})\n```\n\n## Usage\n\n> The API is named as `import.meta.importGlob` to avoid conflict with Vite's `import.meta.glob` in this implementation.\n\n```ts\nconst modules = import.meta.importGlob('./dir/*.js')\n\n/* {\n  './dir/foo.js': () => import('./dir/foo.js'),\n  './dir/bar.js': () => import('./dir/bar.js'),\n} */\n```\n\n#### Multiple Globs\n\n```ts\nconst modules = import.meta.importGlob([\n  './dir/*.js',\n  './another/dir/*.js',\n])\n\n/* {\n  './dir/foo.js': () => import('./dir/foo.js'),\n  './dir/bar.js': () => import('./dir/bar.js'),\n  './another/dir/index.js': () => import('./another/dir/index.js'),\n} */\n```\n\n#### Ignore Glob\n\nGlobs start with `!` will be matched to exclude.\n\n```ts\nconst modules = import.meta.importGlob([\n  './dir/*.js',\n  '!**/index.js',\n])\n```\n\n#### Eager\n\nImport the modules as static imports.\n\n```ts\nconst modules = import.meta.importGlob('./dir/*.js', { eager: true })\n\n/*\nimport * as __glob__0_0 from './dir/foo.js'\nimport * as __glob__0_1 from './dir/bar.js'\nconst modules = {\n  './dir/foo.js': __glob__0_0,\n  './dir/bar.js': __glob__0_1\n}\n*/\n```\n\n#### Import As\n\n```ts\nconst modules = import.meta.importGlob('./dir/*.js', { as: 'raw' })\n\n/* {\n  './dir/foo.js': () => import('./dir/foo.js?raw'),\n  './dir/bar.js': () => import('./dir/bar.js?raw'),\n} */\n```\n\n#### Named Exports\n\nIt's possible to only import parts of the modules with the `export` options.\n\n```ts\nconst setups = import.meta.importGlob('./dir/*.js', { export: 'setup' })\n\n/* {\n  './dir/foo.js': () => import('./dir/foo.js').then(m => m.setup),\n  './dir/bar.js': () => import('./dir/bar.js').then(m => m.setup),\n} */\n```\n\nCombining with `eager`, it's even possible to have tree-shaking enable for those modules.\n\n```ts\nconst setups = import.meta.importGlob('./dir/*.js', { export: 'setup', eager: true })\n\n/*\nimport { setup as __glob__0_0 } from './dir/foo.js'\nimport { setup as __glob__0_1 } from './dir/bar.js'\nconst setups = {\n  './dir/foo.js': __glob__0_0,\n  './dir/bar.js': __glob__0_1\n}\n*/\n```\n\nSet `export` to `default` to import the default export.\n\n```ts\nconst modules = import.meta.importGlob('./dir/*.js', { export: 'deafult', eager: true })\n\n/*\nimport __glob__0_0 from './dir/foo.js'\nimport __glob__0_1 from './dir/bar.js'\nconst modules = {\n  './dir/foo.js': __glob__0_0,\n  './dir/bar.js': __glob__0_1\n}\n*/\n```\n\n#### Custom Queries\n\n```ts\nconst setups = import.meta.importGlob('./dir/*.js', { query: { foo: 'bar', bar: true } })\n\n/* {\n  './dir/foo.js': () => import('./dir/foo.js?foo=bar&bar=true&lang.js').then(m => m.setup),\n  './dir/bar.js': () => import('./dir/bar.js?foo=bar&bar=true&lang.js').then(m => m.setup),\n} */\n```\n\n> **Experimental**: `lang.(ext)` will be added automatically to preseve the file extension for following plugins to process. [Discussions](https://github.com/antfu/vite-plugin-glob/pull/10).\n\n## TypeScript\n\nAdd to `tsconfig.json`\n\n<!-- eslint-skip -->\n\n```jsonc\n{\n  \"compilerOptions\": {\n    \"types\": [\n      \"vite-plugin-glob/client\",\n      // with takeover enabled\n      // \"vite-plugin-glob/takeover\"\n    ]\n  }\n}\n```\n\nYou can use generic to specify the type of the modules.\n\n```ts\ninterface SomeModule {\n  name: string\n  default: { /* ... */ }\n}\n\nimport.meta.importGlob<SomeModule>('./dir/*.js')\n```\n\n## Sponsors\n\n<p align=\"center\">\n  <a href=\"https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg\">\n    <img src='https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg'/>\n  </a>\n</p>\n\n## License\n\n[MIT](./LICENSE) License © 2021 [Anthony Fu](https://github.com/antfu)\n","readmeFilename":"README.md"}