mirror of https://github.com/webpack/webpack.git
feat: added `urlPreloadRegExp`
This commit is contained in:
parent
68e7c698b1
commit
5c847495c6
|
@ -110,15 +110,24 @@ class URLPlugin {
|
||||||
|
|
||||||
/** @type {PreloadOptions} */
|
/** @type {PreloadOptions} */
|
||||||
const preloadOptions = {};
|
const preloadOptions = {};
|
||||||
const { urlPreload, urlPreloadAs, urlFetchPriority } =
|
|
||||||
|
if (
|
||||||
|
parserOptions.urlPreloadRegExp &&
|
||||||
|
parserOptions.urlPreloadRegExp.test(request)
|
||||||
|
) {
|
||||||
|
const { urlPreload, urlPreloadAs, urlPreloadFetchPriority } =
|
||||||
parserOptions;
|
parserOptions;
|
||||||
|
|
||||||
if (urlPreload !== undefined && urlPreload !== false)
|
if (urlPreload !== undefined && urlPreload !== false)
|
||||||
preloadOptions.preloadOrder =
|
preloadOptions.preloadOrder =
|
||||||
urlPreload === true ? 0 : urlPreload;
|
urlPreload === true ? 0 : urlPreload;
|
||||||
if (urlPreloadAs !== undefined && urlPreloadAs !== false)
|
if (urlPreloadAs !== undefined && urlPreloadAs !== false)
|
||||||
preloadOptions.preloadAs = urlPreloadAs;
|
preloadOptions.preloadAs = urlPreloadAs;
|
||||||
if (urlFetchPriority !== undefined && urlFetchPriority !== false)
|
if (
|
||||||
preloadOptions.fetchPriority = urlFetchPriority;
|
urlPreloadFetchPriority !== undefined &&
|
||||||
|
urlPreloadFetchPriority !== false
|
||||||
|
)
|
||||||
|
preloadOptions.fetchPriority = urlPreloadFetchPriority;
|
||||||
|
|
||||||
const { options: importOptions, errors: commentErrors } =
|
const { options: importOptions, errors: commentErrors } =
|
||||||
parser.parseCommentOptions(/** @type {Range} */ (expr.range));
|
parser.parseCommentOptions(/** @type {Range} */ (expr.range));
|
||||||
|
@ -162,19 +171,20 @@ class URLPlugin {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (importOptions.webpackFetchPriority !== undefined) {
|
if (importOptions.webpackPreloadFetchPriority !== undefined) {
|
||||||
if (
|
if (
|
||||||
typeof importOptions.webpackFetchPriority === "string" &&
|
typeof importOptions.webpackPreloadFetchPriority ===
|
||||||
|
"string" &&
|
||||||
["high", "low", "auto"].includes(
|
["high", "low", "auto"].includes(
|
||||||
importOptions.webpackFetchPriority
|
importOptions.webpackPreloadFetchPriority
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
preloadOptions.fetchPriority =
|
preloadOptions.fetchPriority =
|
||||||
importOptions.webpackFetchPriority;
|
importOptions.webpackPreloadFetchPriority;
|
||||||
} else {
|
} else {
|
||||||
parser.state.module.addWarning(
|
parser.state.module.addWarning(
|
||||||
new UnsupportedFeatureWarning(
|
new UnsupportedFeatureWarning(
|
||||||
`\`webpackFetchPriority\` expected true or "low", "high" or "auto", but received: ${importOptions.webpackFetchPriority}.`,
|
`\`webpackFetchPriority\` expected true or "low", "high" or "auto", but received: ${importOptions.webpackPreloadFetchPriority}.`,
|
||||||
/** @type {DependencyLocation} */ (expr.loc)
|
/** @type {DependencyLocation} */ (expr.loc)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -193,6 +203,7 @@ class URLPlugin {
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TODO - `type` and `media` support
|
// TODO - `type` and `media` support
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue