feat: add scheme, mimetype, and resourceFragment rule condition #3238
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.
Related issue (if exists)
fixes #3150
Summary
🤖 Generated by Copilot at 8d60263
This pull request adds a new hook to the
rspack
compiler that allows plugins to customize the resolution of resources with different schemes, such asdata
,file
, orhttp
. It also updates thenode_binding
crate to support the new hook in the Node.js integration, and adds or modifies several plugins to handle different types of asset modules. Additionally, it improves the code quality and readability of some structs and methods in therspack_core
,rspack_binding_options
, andrspack_loader_runner
crates.Walkthrough
🤖 Generated by Copilot at 8d60263
resource_fragment
,scheme
, andmimetype
to theModuleRule
andRawModuleRule
structs to allow specifying condition matchers for the resource fragment, the scheme, and the mimetype in the module rules (link, link, link, link, link, link, link)normal_module_factory_resolve_for_scheme
to theHook
enum and thePlugin
trait to allow plugins to customize the resolution of resources with different schemes (link, link, link, link, link, link, link, link)normal_module_factory_resolve_for_scheme
hook to include a flag to indicate whether to stop the resolution process (link, link, link, link, link, link, link, link, link)Scheme::Normal
variant toScheme::None
and handle the empty string case in theScheme
enum (link, link, link, link, link)mime_guess
crate to guess the mime type of resources based on their file extensions (link, link, link)urlencoding
crate to encode and decode binary data as URL-safe strings (link, link, link, link)let_chains
feature to writeif let
andmatch
expressions in a chain (link, link)serde_json
crate to serialize the encoded source as a JSON string in theAssetParserAndGenerator
struct (link, link)JsPathData
struct by removing thequery
andfragment
fields and updating the methods accordingly (link, link)Debug
implementation for theModuleRule
struct by using thederivative
crate and a customformat_with
attribute for ther#use
field (link)AssetParserAndGenerator
struct (link, link, link, link, link)normal_module_factory_resolve_for_scheme
hook for each plugin and returning the final resolved data and the flag in thePluginDriver
struct (link)normal_module_factory_resolve_for_scheme
hook from the Rust and JavaScript sides using thenapi
crate in theJsPlugin
andJsHooks
structs (link, link, link, link)resource_fragment
,scheme
, andmimetype
fields from theRawModuleRule
struct to theModuleRule
struct in thetry_into
method (link, link)try_match
method of theModuleRule
struct (link)data
scheme in themut
function of theFilename
struct (link)data
scheme in theparse
method of theImportDependency
struct by using theparse_resource
function (link)data
scheme in thecopy
method of theCopyPlugin
struct by skipping the asset path generation and the asset info insertion (link)copy
method of theCopyPlugin
struct by using theto_string_lossy
method for thesource_filename
(link)Debug
implementation for theModuleIdentifier
struct (link)SchemeAndJsResourceData
toJsResolveForSchemeInput
to make the name more descriptive and consistent with the new hook name (link, link, link)std::path::Path
in thepath_data.rs
file (link)PluginNormalModuleFactoryResolveForSchemeOutput
in theplugin_driver.rs
file (link)parse
method of theImportDependency
struct (link)