Open IlyaSemenov opened 1 year ago
Hi. This is a Vite feature but we might be able to replicate it with a rollup plugin 👍🏼
Side-note: As for laziness, please strictly consider to avoid any side-effect logics inside js modules even when they are dynamically imported. defineLazyHandler
can do the trick!
Try https://github.com/sxzz/unplugin-glob
If you prefer vite-style glob imports, I'm willing to create an unplugin for that
@so1ve I'd prefer to have vite-style imports to reuse code between Vite and Nuxt. My use-case is a lot of graphql resolvers in individual modules which I gather with import.meta.glob in Vite. In dev mode, I'd like these handlers to be served by Nuxt dev server, and for that I need it to understand vite import syntax.
@pi0 have there been any updates regarding the use of import.meta.glob
in the meantime?
@tschni it is likely we will support it only with nitro v3 via vite bundler.
In the meantime, i think an unplugin like the one @sxzz made unplugin-glob should make it doable.
Oh this one is made by @sxzz :)
@so1ve Did you actually try that plugin with Nuxt? I'm struggling to make it work. When I add this to nuxt.config.ts
:
import UnpluginGlob from 'unplugin-glob/vite';
export default defineNuxtConfig({
vite: {
plugins: [UnpluginGlob({})],
},
});
and then:
import * as all from 'glob:name:./parts/*.ts';
It doesn't work:
[2:51:22 PM] ERROR Pre-transform error: Failed to resolve import "glob:name:./parts/*.ts" from "app.vue". Does the file exist?
See minimal reproduction: https://stackblitz.com/edit/nuxt-starter-farkra
关于这个红色提示的问题我在 tsconfig.json 文件中添加 "compilerOptions": { "module": "esnext", // 主要是这个
}, 获得了解决
Describe the feature
Following https://github.com/nuxt/nuxt/issues/22106, I would like to have
import.meta.glob("./migrations/*.ts")
available in Nitro apps, in particular in Nuxt server handlers.As I elaborated in #1670, this should be lazy by default, repeating how Vite works. An option to pass
{ eager: true }
(same as in Vite) would be nice but not critical, as this could be achieved in user-land.Additional information