-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat!: rework import.meta.glob
#7537
Conversation
vite-plugin-glob
It's possible to only import parts of the modules with the `import` options. | ||
|
||
```ts | ||
const modules = import.meta.glob('./dir/*.js', { import: 'setup' }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are multiple imports supported with an array? Should we add a section about this or maybe just use it in the example?
const modules = import.meta.glob('./dir/*.js', { import: 'setup' }) | |
const modules = import.meta.glob('./dir/*.js', { import: ['setup', 'render'] }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it does not support arrays. Referring to the eager: true
example, the named import will be directly used as the value instead of the "Module" object. For multiple named imports they might better use multiple statements.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gotcha. Sound good since most of the cases when using glob would require a single import, so looks good to me to wait until users request the feature. We could support both string or array if we need to go there anyway.
Co-authored-by: patak <matias.capeletto@gmail.com>
```ts | ||
const modules = import.meta.glob('./dir/*.js', { | ||
query: { foo: 'bar', bar: true } | ||
}) | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a note, it would be good to avoid the name query
since the way we add metadata/modifiers to imports is probably going to change in the future. But overriding as
to allow for multiple values doesn't sound future-proof, and any other more generic name may actually end up conflicting with whatever gets standardized in the end. I thought of metadata
, modifiers
, with
... we still have time until v3 to bike shed a bit if we find a more generic name that we are sure will not collide later. But for the moment, I think we can move forward with query
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess unless we are going to break our convention of using queries in v3.0, maybe naming it as query
is still the most intuitive way to do it. In the future, if we find an alternative that does not use queries, (if it's not v3, probably v4) we could break this to align. It might be hard for now to foresee what's the format we gonna use in the future.
} | ||
scripts[key] = { | ||
loader, | ||
contents |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the one place that I'm still unsure it won't affect us. It is strange to me that if a user has:
import 'module-a.js'
import 'module-b.js'
And modifies the code to
import.meta.glob('module-?.js', { eager: true })`
Then scanning would be affected.
Or is this already taken care of in the PR? 🤔
Would it be possible to run the glob plugin when import.plugin.glob
is present before this analysis if not?
This is awesome 🚀 |
Linking for reference a discussion to stabilize cc @brillout |
The output that Yesterday I ended up writing my own Vite plugin yesterday to manually export and control the names and formats of the exports in my library entry file. My local plugin was highly inspired (read: copy pasted) from other plugins in our ecosystem that use the Vite server watcher + Is there an easy way to do this that I missed? I dug through rollup + vite plugin docs and other plugins for like 6-10 straight hours yesterday I was mainly looking at:
@patak-dev any thoughts? |
@JessicaSachs Anthony sent a PR to tackle a similar issue here: That PR is a good place to continue the discussion. @antfu presented the PR yesterday in the last Vite team meeting, but it wasn't clear to the group if it should be included in core, or keep it as a plugin. Maybe it would be good to copy your comment there 👍🏼 |
I am currently using |
Is there any change that I think it also solves #7537 (comment) |
Description
Port https://github.com/antfu/vite-plugin-glob to the core.
Rendered docs
Close #8032
TODO
vite-plugin-glob
import.meta.glob
handlingvite-plugin-glob
to core.Notes for Changelog
Breaking changes
import.meta.glob
are now relative to the current module.import.meta.glob
, the keys are always absolute.Features
Glob Import Rework
Based on the experiments we made in
vite-plugin-glob
, it's now part of the Vue 3 core with the enhancements:import.meta.globEager
are unified asimport.meta.glob('pattern', { eager: true })
eager: true
.Learn more at Glob Import