Closed tmg0 closed 2 months ago
Why can’t you use the exposed plugin directly? Rspack is supported
Thank you for your response.
I tried using unplugin-vue-router
with rspack
directly, but I encountered some issues. I've opened an issue in the rspack
repo, and it seems the problem lies in unplugin rspack virtual.
unplugin-vue-router
is a really awesome package, so I'd like to find some other ways to use it.
ERROR in ./node_modules/.pnpm/unplugin@1.12.3/node_modules/unplugin/dist/rspack/virtual.js?unplugin_rspack_virtual=%2F__vue-router%2Fauto-routes
× Module parse failed:
╰─▶ × JavaScript parsing error: 'import', and 'export' cannot be used outside of module code
╭─[1:0]
1 │ export const routes = [
· ──────
2 │ {
3 │ path: '/',
╰────
help:
File was processed with these loaders:
* commonjs|/nuxlite/node_modules/.pnpm/unplugin@1.12.3/node_modules/unplugin/dist/rspack/loaders/load.js??ruleSet[1].rules[2].use[0]
You may need an additional loader to handle the result of these loaders.
I see. The module should be usable. There is no getting around the virtual modules for it to work, so even if more parts of the code are exposed, it will still not work.
Note that even createRoutesContext
is not documented, it's an internal feature too and could change in any version. I would suggest that you don't use it. You can copy the code of resolveOptions if you want to play around until virtual modules are supported but I think you will find other blockers.
Note that this library has many more improvements like HMR that only work with Vite. So I recommend you to use it with Vite if you can too
Thank you very much for your suggestion! I will still use Vite in production to avoid unknown issues.
Recently, I've been using unplugin-vue-router and rspack to build my application, but I've met some issues. So I'm trying to generating route records and inject to a virtual file manually.
I found that
unplugin-vue-router
exports acreateRoutesContext
function, but its parameters have already been processed byresolveOptions
and undergone complex manipulations. This makescreateRoutesContext
virtually unusable directly.I'm wondering if it would be possible to export the
resolveOptions
method, or move this into thecreateRoutesContext
?If it's possable, I'm glad to contribute a PR to improve this situation.