-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
fix(nuxt): make autoImport work with minified code #32298
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR ensures auto-imports work correctly when code is minified by esbuild’s minifyWhitespace
option.
- Updated the component loader’s regex to match
resolveComponent
calls in minified output. - Added a new test case in
component-loader.test.ts
to verify behavior under whitespace minification. - Refactored the test file to initialize the loader plugin once and reuse it in the transform helper.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
File | Description |
---|---|
packages/nuxt/test/component-loader.test.ts | Added test for minified code and extracted plugin setup for reuse. |
packages/nuxt/src/components/plugins/loader.ts | Broadened the resolveComponent regex to handle minified calls. |
Comments suppressed due to low confidence (3)
packages/nuxt/test/component-loader.test.ts:61
- [nitpick] The inline snapshot is very large and tightly coupled to exact formatting, making the test brittle. Consider using more focused assertions (e.g.
toContain
or regex) on key snippets rather than matching the full code text.
const content = `import { createHotContext as __vite__createHotContext } from "/_nuxt/@vite/client";import.meta.hot = __vite__createHotContext("/app.vue");...`
packages/nuxt/src/components/plugins/loader.ts:24
- [nitpick] The regex for matching minified
resolveComponent
calls is complex and hard to read. Consider breaking it into named pieces or adding an explanatory comment to improve readability and maintainability.
const REPLACE_COMPONENT_TO_DIRECT_IMPORT_RE = /(?<=[\s(=;])_?resolveComponent\s*\(\s*(?<quote>["'`])(?<lazy>lazy-|Lazy(?=[A-Z]))?.../g
WalkthroughThe changes update a regular expression in the loader plugin to broaden its matching criteria for 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Yes, it might make sense to disable this optimisation in dev mode. Can you think of a reason someone might want to set it then? |
@nuxt/kit
nuxt
@nuxt/rspack-builder
@nuxt/schema
@nuxt/vite-builder
@nuxt/webpack-builder
commit: |
No, I think we can disable it safely. |
yes, it seems it would still be beneficial! |
CodSpeed Performance ReportMerging #32298 will not alter performanceComparing Summary
|
🔗 Linked issue
fix #32290
📚 Description
This PR makes autoImport work with minified code.
But should we not allow esbuild.minifyWhitespace to be set to true since it's used only in dev ?