You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In my understanding, virtual modules do not actually exist in the file system, so real files imported from the file system should use their absolute paths. Although vite also handles the use of relative paths when importing, edge cases like in this example cannot be avoided.
So I propose to add an option to specify the import path in the generated virtual module as an absolute path or a relative path
Suggested solution
Modify the Options type and add the importPath: 'absolute' | 'relative' attribute
Modify the resolveOptions function to provide the default value 'relative' for the importPath attribute, that is, keep the current import path unchanged
Modify computeReactRoutes, computeVueRoutes, computeSolidRoutes functions to check the importPath attribute before using page.path.replace(ctx.root, '') to convert the path
Description
I have a sample project with the project structure as follows:
The content of the automatically generated
virtual:vite-plugin-pages/generated-pages?id=~react-pages
virtual module is as follows:The import path is
/src/pages/App.tsx
, which is regarded as a relative path relative to the project root directory.However, in vite's import-analysis plugin, the path will first be
stripBase
, see for details: https://github.com/vitejs/vite/blob/86cf1b4b497557f09a0d9a81dc304e7a081d6198/packages/vite/src/node/plugins/importAnalysis.ts#L298, this makes the module unable to be resolved.In my understanding, virtual modules do not actually exist in the file system, so real files imported from the file system should use their absolute paths. Although vite also handles the use of relative paths when importing, edge cases like in this example cannot be avoided.
So I propose to add an option to specify the import path in the generated virtual module as an absolute path or a relative path
Suggested solution
Options
type and add theimportPath: 'absolute' | 'relative'
attributeresolveOptions
function to provide the default value'relative'
for theimportPath
attribute, that is, keep the current import path unchangedcomputeReactRoutes
,computeVueRoutes
,computeSolidRoutes
functions to check theimportPath
attribute before usingpage.path.replace(ctx.root, '')
to convert the pathAlternative
No response
Additional context
No response
Validations
The text was updated successfully, but these errors were encountered: