antfu / vite-plugin-glob

The design experiment for import.meta.glob from Vite.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Make paths relative from `config.root`

brillout opened this issue · comments

commented

If we merge #5 then I would propose this:

// Pre-transform
import.meta.importGlob('/**/*.page.js')

// Post-transform today
{
  "../../../../../examples/vue/renderer/_default.page.client.js": () =>
    import("../../../../../examples/vue/renderer/_default.page.client.js")
}

// Post-transform proposal (`config.root` being `'/examples/vue/'`)
{
  "/renderer/_default.page.client.jsx": () =>
    import("../../../../../examples/vue/renderer/_default.page.client.jsx")
}

This is what Vite does today.

Is that when the glob is / the so as the object key, or has it always been relative to /? Or maybe it's worth making it configurable?

commented

Yes Vite does that when the glob starts with /. (Less sure otherwise.)

Regardless of Vite, I'd say that a sensible default is to preserve the glob syntax:

import.meta.importGlob('/**/*.js')
// Post-transform
{ "/path/to/some.js": () => import(/* ... */) }

import.meta.importGlob('./**/*.js')
// Post-transform
{ "./path/to/some.js": () => import(/* ... */) }

// We currently don't support that syntax, but in case we want to in the future:
import.meta.importGlob('**/*.js')
// Post-transform
{ "path/to/some.js": () => import(/* ... */) }

I'd say that this is what I would expect as a user.

Proposal: #7. It also includes a new option filePathsRelativeToRoot.

commented

Implemented by #7.