Make paths relative from `config.root`
brillout opened this issue · comments
Rom 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.
Anthony Fu commented
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?
Rom 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
.