diff --git a/lib/dependencies/URLPlugin.js b/lib/dependencies/URLPlugin.js index 709465887..03fa15057 100644 --- a/lib/dependencies/URLPlugin.js +++ b/lib/dependencies/URLPlugin.js @@ -50,7 +50,14 @@ class URLPlugin { */ const handler = (parser, parserOptions) => { if (parserOptions.url === false) return; - new URLParserPlugin(parserOptions).apply(parser); + const externalsPresets = compilation.options.externalsPresets || {}; + const enableUrlAssetHints = Boolean( + externalsPresets.web || externalsPresets.webAsync + ); + new URLParserPlugin({ + ...parserOptions, + enableUrlAssetHints + }).apply(parser); }; normalModuleFactory.hooks.parser diff --git a/lib/url/URLParserPlugin.js b/lib/url/URLParserPlugin.js index 3576b1e0f..f8ed143d5 100644 --- a/lib/url/URLParserPlugin.js +++ b/lib/url/URLParserPlugin.js @@ -106,6 +106,7 @@ class URLParserPlugin { */ apply(parser) { const relative = this.options.url === "relative"; + const enableUrlAssetHints = Boolean(this.options.enableUrlAssetHints); parser.hooks.canRename.for("URL").tap(PLUGIN_NAME, approve); parser.hooks.evaluateNewExpression.for("URL").tap(PLUGIN_NAME, (expr) => { @@ -188,7 +189,7 @@ class URLParserPlugin { if (importOptions) { // Accept only boolean true for webpackPrefetch if (importOptions.webpackPrefetch === true) { - dep.prefetch = true; + if (enableUrlAssetHints) dep.prefetch = true; } else if (importOptions.webpackPrefetch !== undefined) { parser.state.module.addWarning( new UnsupportedFeatureWarning( @@ -200,7 +201,7 @@ class URLParserPlugin { // Accept only boolean true for webpackPreload if (importOptions.webpackPreload === true) { - dep.preload = true; + if (enableUrlAssetHints) dep.preload = true; } else if (importOptions.webpackPreload !== undefined) { parser.state.module.addWarning( new UnsupportedFeatureWarning( @@ -215,7 +216,9 @@ class URLParserPlugin { typeof importOptions.webpackFetchPriority === "string" && ["high", "low", "auto"].includes(importOptions.webpackFetchPriority) ) { - dep.fetchPriority = importOptions.webpackFetchPriority; + if (enableUrlAssetHints) { + dep.fetchPriority = importOptions.webpackFetchPriority; + } } else if (importOptions.webpackFetchPriority !== undefined) { parser.state.module.addWarning( new UnsupportedFeatureWarning(