Move ineffective dynamic import warning from plugin to core#7530
Move ineffective dynamic import warning from plugin to core#7530
Conversation
✅ Deploy Preview for rolldown-rs canceled.
|
- Created new BuildDiagnostic event `IneffectiveDynamicImport` - Added check_ineffective_dynamic_imports method in GenerateStage - Removed warning logic from vite_reporter plugin - Added rolldown_plugin_utils dependency to rolldown crate Co-authored-by: sapphi-red <49056869+sapphi-red@users.noreply.github.com>
Co-authored-by: sapphi-red <49056869+sapphi-red@users.noreply.github.com>
- Build lookup map of module_id -> chunk modules for O(1) lookups - Use pointer comparison to check if modules are in same chunk - Reduced complexity from O(n*m*k) to O(n*m) Co-authored-by: sapphi-red <49056869+sapphi-red@users.noreply.github.com>
- Store ChunkIdx instead of Vec reference in lookup map - Use chunk index comparison for more robust checking - Update comment to accurately reflect what is being stored Co-authored-by: sapphi-red <49056869+sapphi-red@users.noreply.github.com>
Co-authored-by: sapphi-red <49056869+sapphi-red@users.noreply.github.com>
|
@copilot can we emit the warning when we actually move the dynamically imported module |
The warning is currently emitted when a module has both static and dynamic importers in the same chunk. This indicates the dynamic import won't split the module into a separate chunk because it's already statically imported. Could you clarify what you mean by "when we actually move the dynamically imported module"? Are you asking to:
The current logic matches the original vite_reporter behavior - it checks if both |
|
@copilot "2. Move the warning to a different location in the code?" is what I mean |
Moved ineffective dynamic import warning from generate() to split_chunks() where modules are actually assigned to chunks. This provides better context and timing for the warning - it's now emitted when we assign a module to a chunk and detect it has dynamic importers in the same chunk. Changes: - Removed check from GenerateStage::generate() - Added warning check in split_chunks() loop during module assignment - Made check_ineffective_dynamic_import_for_module a static method - Collect warnings during loop and add to link_output after - Changed split_chunks to &mut self to allow warning collection Co-authored-by: sapphi-red <49056869+sapphi-red@users.noreply.github.com>
Moved the warning emission to the code splitting phase in commit 7fdf753. The warning is now emitted in The key change is checking for ineffective dynamic imports right after adding a module to an existing chunk (line 777-789), where we can immediately detect if any of its dynamic importers are also in that chunk. |
The warning for ineffective dynamic imports was incorrectly placed in the
vite_reporterplugin'srender_chunkhook. This is core bundling logic that should execute regardless of which reporter is used.Changes
IneffectiveDynamicImportinrolldown_errorwithjoin_with_limitutility for formatting module listssplit_chunks()method during module assignment to chunks, emitting warnings when modules with dynamic importers are placed in the same chunk as those importerscheck_ineffective_dynamic_import_for_module()checks each module during chunk assignment without global iteration overheadvite_reporter, simplified to pure logging responsibilitiesImplementation
The check detects when a module has both static and dynamic importers in the same chunk during the code splitting phase:
The warning is now emitted in
code_splitting.rsduring thesplit_chunks()phase (lines 749-804) when modules are actually being assigned to chunks, providing better timing and context. Filters outnode_modulesto avoid noise from third-party dependencies.Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.