-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
[Feature request] Allow import.meta.glob from node_modules #5728
Comments
Did you ever find a work around? I have run in to the same issue trying to import some language files from a node_module to use in a i18n language switcher. |
My work-around was to clone my other project into a sub-folder within my main project, which is ugly and a bit painful to manage, but is working. |
Eek, I was worried that is what you might say. For me it is importing of language files so will become a pain for tracking changes on package updates, but haven't come up with anything better yet. +1 for allowing import.meta.glob from node_modules |
Vite currently has a pre-bundling process that generally forbids anything that invoking a plugin to work, i.e. it requires all third-party libraries to be "production" code without being bound to some specific bundler. An workaround is using symlinks to link some module in node_modules to somewhere out of it, in which case vite will treat that module as user code so it won't optimize it. |
Interesting approach, thanks for the input. Of course not ideal, but will give it some thought. I can provide an example here of use case. I came across the issue because I am using Quasar, which provides a bunch of components out of the box for developing Vue sites. Some of these components include things like tables, menu items and so forth. These stock components have labels on them which are standard for all users, such as pagination on tables which have default https://quasar.dev/options/quasar-language-packs#dynamical-non-ssr- |
I think this feature is supported since #6056. |
Following this: https://vitejs.dev/guide/features.html#glob-import
Produces this:
|
I guess that's because using Maybe the vite server could add a quick test about if the served file is in commonjs, run esbuild.transform() to turn it to esm. |
A working example using the glob pattern provided here: quasarframework/quasar#12911 (comment) Seems like it is allowing the imports from node_modules, must have been something I was doing wrong with my example. Looks like it is that I was importing the .js files instead of .mjs, so as mentioned above importing from commonjs modules ( |
FYI, this is working for me in a SvelteKit app. I was able to use |
Closing as this is reported to be working. Thanks y'all who helped verify this! Re #5728 (comment), @Maggie0002 if you're importing files that aren't esm from the node_modules, you need to explicitly optimize them by placing the individual files in
@hyrious Vite's philosophy around dealing with CJS is that they should be prebundled first before the source code interacts with it, so it's unlikely that we would transpile with esbuild on-the-fly. Using |
Clear and concise description of the problem
I'm building a site that relies on some data that I would like to include via an npm install. These are markdown pages in a separate repo. Ideally, I'd be able to
import.meta.glob('my-dependency/**/*.md')
to access these files, but this is an invalid syntax. And trying/node_modules/my-dependency/**/*.md
does not work either.I guess this is probably because node_modules are specifically ignored, perhaps? 8b3d0ea
Suggested solution
I'm not sure how this would be accomplished, or whether it's even possible, honestly.
Alternative
My other option is to use git submodules to include my markdown files from the other repo, but I'd really rather not use submodules if I can help it.
Additional context
No response
Validations
The text was updated successfully, but these errors were encountered: