mirror of https://github.com/webpack/webpack.git
fix: only enable URL asset prefetch/preload hints for web targets
This commit is contained in:
parent
e97ae49459
commit
e7c0382087
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
) {
|
||||
if (enableUrlAssetHints) {
|
||||
dep.fetchPriority = importOptions.webpackFetchPriority;
|
||||
}
|
||||
} else if (importOptions.webpackFetchPriority !== undefined) {
|
||||
parser.state.module.addWarning(
|
||||
new UnsupportedFeatureWarning(
|
||||
|
|
Loading…
Reference in New Issue