feat: loaderContext.loadModule #10532
Open
+1,011
−18
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR implements
loaderContext.loadModule
feature. It references the implementation ofloaderContext.importModule
.How webpack does it
Webpack
LoaderContex.importModule
implementation is relatively simplerecursive: false
to prevent submodule creation ( code )Implementation details
Rspack's implementation of loadModule is similar to that of importModule, both using an implementation that is completely independent of make moduleGraph.
Overwrite Task
The Overwrite Task is mainly used to overwrite the task defined by Make while retaining its functionality
Module Tracker
Module Tracker records and tracks the construction of the Module through OverwriteTask. Compared with the implementation of ImportModule, this implementation is simpler because the modules are all isolated nodes.
ModuleTracker records all running entry_dependencies and their executeTask,
Cleanup Task
Since there are only isolated nodes in the module graph, the clearing methods need to be implemented separately.
CleanModuleTask
The module cleanup task is mainly to delete the old module before loadModule is executed. Since all nodes are isolated nodes, the entry_dependency can be deleted together while deleting the unnecessary module.
CleanEntryTask
The clear Entry task is used to delete the Entry that is no longer used by revoke_module at the end of make.
Main Process of Module Loader
Suspend task_loop and add CleanModuleTask and CtrlTask. CtrlTask is responsible for dynamically adding external tasks to the task queue.
By passing CleanEntryTask to the task queue at the end of make, the task queue will exit after execution.
Checklist