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} */
|
||||
const preloadOptions = {};
|
||||
const { urlPreload, urlPreloadAs, urlFetchPriority } =
|
||||
|
||||
if (
|
||||
parserOptions.urlPreloadRegExp &&
|
||||
parserOptions.urlPreloadRegExp.test(request)
|
||||
) {
|
||||
const { urlPreload, urlPreloadAs, urlPreloadFetchPriority } =
|
||||
parserOptions;
|
||||
|
||||
if (urlPreload !== undefined && urlPreload !== false)
|
||||
preloadOptions.preloadOrder =
|
||||
urlPreload === true ? 0 : urlPreload;
|
||||
if (urlPreloadAs !== undefined && urlPreloadAs !== false)
|
||||
preloadOptions.preloadAs = urlPreloadAs;
|
||||
if (urlFetchPriority !== undefined && urlFetchPriority !== false)
|
||||
preloadOptions.fetchPriority = urlFetchPriority;
|
||||
if (
|
||||
urlPreloadFetchPriority !== undefined &&
|
||||
urlPreloadFetchPriority !== false
|
||||
)
|
||||
preloadOptions.fetchPriority = urlPreloadFetchPriority;
|
||||
|
||||
const { options: importOptions, errors: commentErrors } =
|
||||
parser.parseCommentOptions(/** @type {Range} */ (expr.range));
|
||||
|
@ -162,19 +171,20 @@ class URLPlugin {
|
|||
);
|
||||
}
|
||||
}
|
||||
if (importOptions.webpackFetchPriority !== undefined) {
|
||||
if (importOptions.webpackPreloadFetchPriority !== undefined) {
|
||||
if (
|
||||
typeof importOptions.webpackFetchPriority === "string" &&
|
||||
typeof importOptions.webpackPreloadFetchPriority ===
|
||||
"string" &&
|
||||
["high", "low", "auto"].includes(
|
||||
importOptions.webpackFetchPriority
|
||||
importOptions.webpackPreloadFetchPriority
|
||||
)
|
||||
) {
|
||||
preloadOptions.fetchPriority =
|
||||
importOptions.webpackFetchPriority;
|
||||
importOptions.webpackPreloadFetchPriority;
|
||||
} else {
|
||||
parser.state.module.addWarning(
|
||||
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)
|
||||
)
|
||||
);
|
||||
|
@ -193,6 +203,7 @@ class URLPlugin {
|
|||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO - `type` and `media` support
|
||||
|
||||
|
|
Loading…
Reference in New Issue