I'm having a hard time understanding the explanation given by the docs:
Rule.typesets the type for a matching module. This prevents defaultRules and their default importing behaviors from occurring. For example, if you want to load a.jsonfile through a custom loader, you'd need to set thetypetojavascript/autoto bypass webpack's built-in json importing.
If I understood it correctly, the purpose of Rule.type is to override the defaultRules (whichever they are, I couldn't find any info about them anywhere). But it doesn't make sense because:
- There is a type,
json, which I think should be used for.jsonfiles, instead ofjavascript/auto. If the purpose is to override the default rules, wouldn't it be better to create and use aoverrideDefaultRulesboolean field instead of specifying a wrong type? - What are those default rules we are overriding anyways?
In the documentation for Asset Modules, it is said that...
Asset Modules type replaces all of these loaders by adding 4 new module types:
- asset/resource emits a separate file and exports the URL. Previously achievable by using file-loader.
- asset/inline exports a data URI of the asset. Previously achievable by using url-loader.
- asset/source exports the source code of the asset. Previously achievable by using raw-loader.
- asset automatically chooses between exporting a data URI and emitting a separate file. Previously achievable by using url-loader with asset size limit.
When using the old assets loaders (i.e. file-loader/url-loader/raw-loader) along with Asset Module in webpack 5, you might want to stop Asset Module from processing your assets again as that would result in asset duplication. This can be done by setting asset's module type to 'javascript/auto'.
If the whole point of this new Asset Module is to do what the loaders did, why would anyone use both the Asset Module and the loaders, as the last paragraph suggests? And... wouldn't it be better if instead of using the 'javascript/auto' hack we just didn't include the Aset Modules in the first place? And doesn't it look like for the specific case of the assets, the whole point of the type was to do the exact same thing you did with loaders but using the type field instead? You can specify the asset type and let it automatically choose between asset/resource and asset/inline, but then again, What value would the other types actually add then? What is it that I am missing? Is there maybe anything else the type does that is not specified in the documentation or something?