Repository navigation
fix(unplugin): support definePage with webpack and rspack - #2829
Conversation
The `?definePage` import of `.vue` pages still matched the `.vue` rule in webpack and rspack, so vue-loader tried to compile the extracted route data as an SFC and failed. Use an inline match resource so the module goes through the tsx rules instead. See posva/unplugin-vue-router#531
✅ Deploy Preview for vue-router canceled.
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (6)
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review. 📝 WalkthroughWalkthroughThe plugin now uses framework metadata when generating definePage import IDs. Vue and non-Vue files receive IDs based on their language and framework, and the definePage query matcher accepts queries containing ChangesFramework-aware definePage imports
Priority: ➖ Normal Estimated code review effort: 3 (Moderate) | ~20 minutes Change: Bug fix Sequence Diagram(s)sequenceDiagram
participant Unplugin
participant RouteCodegen
participant getDefinePageImportId
participant WebpackRspackLoaders
Unplugin->>RouteCodegen: Pass framework in resolved options
RouteCodegen->>getDefinePageImportId: Request ID for a Vue file
getDefinePageImportId-->>RouteCodegen: Return .definePage.tsx match-resource ID
RouteCodegen->>WebpackRspackLoaders: Emit request chained through original Vue loader request
WebpackRspackLoaders->>WebpackRspackLoaders: Match extracted module against TSX loader rules
Suggested reviewers: Merge Risk: ⚪ Minimal · up to This change fixes definePage handling under webpack and rspack by routing the extracted module through TSX rules. No actionable merge-blocking risk was found in the supplied context. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
commit: |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2829 +/- ##
==========================================
+ Coverage 88.07% 88.23% +0.16%
==========================================
Files 78 78
Lines 6289 6292 +3
Branches 2041 2041
==========================================
+ Hits 5539 5552 +13
+ Misses 661 651 -10
Partials 89 89 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Fixes
definePage()with webpack and rspack/rsbuild. Originally reported in posva/unplugin-vue-router#531; it still happens withvue-router@5.4.0.Problem
For
.vuepages, the generated routes import the route data aspage.vue?definePage&vue&lang.tsx. webpack and rspack match rules against the file path, so this module still goes through the.vuerule, and thevuequery also triggers vue-loader's pitcher. The plugin'spretransform has already reduced the module toexport default { ... }, so vue-loader fails:Fix
With webpack and rspack, the import uses an inline match resource, the same mechanism vue-loader uses for SFC blocks:
Rules now match
page.vue.definePage.tsx, so the.vuerule and vue-loader's pitcher skip it and the tsx rules strip any TS. The loaders still read the realpage.vue?definePage&vue&lang.tsx, sodefinePageTransformis unchanged. Vite and the other bundlers keep the current id.Other changes:
meta.frameworkthrough a new internal_frameworkoption.generateRouteRecordsandgenerateRouteResolver) now share a singlegetDefinePageImportId()helper.DEFINE_PAGE_QUERY_REno longer requires&vue, so the transform rule also matches the match resource id. That id can't contain avueparam, or vue-loader's pitcher would pick it up again.Testing
vitest run src/unplugin,test:typesandlintpass.@rsbuild/plugin-vue2.0.1: the build fails on 5.4.0 and passes with this branch.metafromdefinePage()ends up in the route records, including with TS syntax (as const) in alang="ts"page.Summary by CodeRabbit