mirror of https://github.com/webpack/webpack.git
feat: added `urlPreloadRegExp`
This commit is contained in:
parent
68e7c698b1
commit
5c847495c6
|
@ -110,90 +110,101 @@ class URLPlugin {
|
||||||
|
|
||||||
/** @type {PreloadOptions} */
|
/** @type {PreloadOptions} */
|
||||||
const preloadOptions = {};
|
const preloadOptions = {};
|
||||||
const { urlPreload, urlPreloadAs, urlFetchPriority } =
|
|
||||||
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;
|
|
||||||
|
|
||||||
const { options: importOptions, errors: commentErrors } =
|
if (
|
||||||
parser.parseCommentOptions(/** @type {Range} */ (expr.range));
|
parserOptions.urlPreloadRegExp &&
|
||||||
|
parserOptions.urlPreloadRegExp.test(request)
|
||||||
|
) {
|
||||||
|
const { urlPreload, urlPreloadAs, urlPreloadFetchPriority } =
|
||||||
|
parserOptions;
|
||||||
|
|
||||||
if (commentErrors) {
|
if (urlPreload !== undefined && urlPreload !== false)
|
||||||
for (const e of commentErrors) {
|
preloadOptions.preloadOrder =
|
||||||
const { comment } = e;
|
urlPreload === true ? 0 : urlPreload;
|
||||||
|
if (urlPreloadAs !== undefined && urlPreloadAs !== false)
|
||||||
|
preloadOptions.preloadAs = urlPreloadAs;
|
||||||
|
if (
|
||||||
|
urlPreloadFetchPriority !== undefined &&
|
||||||
|
urlPreloadFetchPriority !== false
|
||||||
|
)
|
||||||
|
preloadOptions.fetchPriority = urlPreloadFetchPriority;
|
||||||
|
|
||||||
|
const { options: importOptions, errors: commentErrors } =
|
||||||
|
parser.parseCommentOptions(/** @type {Range} */ (expr.range));
|
||||||
|
|
||||||
|
if (commentErrors) {
|
||||||
|
for (const e of commentErrors) {
|
||||||
|
const { comment } = e;
|
||||||
|
parser.state.module.addWarning(
|
||||||
|
new CommentCompilationWarning(
|
||||||
|
`Compilation error while processing magic comment(-s): /*${comment.value}*/: ${e.message}`,
|
||||||
|
comment.loc
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (importOptions) {
|
||||||
|
if (importOptions.webpackPreload !== undefined) {
|
||||||
|
if (importOptions.webpackPreload === true) {
|
||||||
|
preloadOptions.preloadOrder = 0;
|
||||||
|
} else if (typeof importOptions.webpackPreload === "number") {
|
||||||
|
preloadOptions.preloadOrder = importOptions.webpackPreload;
|
||||||
|
} else {
|
||||||
|
parser.state.module.addWarning(
|
||||||
|
new UnsupportedFeatureWarning(
|
||||||
|
`\`webpackPreload\` expected true or a number, but received: ${importOptions.webpackPreload}.`,
|
||||||
|
/** @type {DependencyLocation} */ (expr.loc)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (importOptions.webpackPreloadAs !== undefined) {
|
||||||
|
if (typeof importOptions.webpackPreloadAs === "string") {
|
||||||
|
preloadOptions.preloadAs = importOptions.webpackPreloadAs;
|
||||||
|
} else {
|
||||||
|
parser.state.module.addWarning(
|
||||||
|
new UnsupportedFeatureWarning(
|
||||||
|
`\`webpackPreloadAs\` expected string, but received: ${importOptions.webpackPreloadAs}.`,
|
||||||
|
/** @type {DependencyLocation} */ (expr.loc)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (importOptions.webpackPreloadFetchPriority !== undefined) {
|
||||||
|
if (
|
||||||
|
typeof importOptions.webpackPreloadFetchPriority ===
|
||||||
|
"string" &&
|
||||||
|
["high", "low", "auto"].includes(
|
||||||
|
importOptions.webpackPreloadFetchPriority
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
preloadOptions.fetchPriority =
|
||||||
|
importOptions.webpackPreloadFetchPriority;
|
||||||
|
} else {
|
||||||
|
parser.state.module.addWarning(
|
||||||
|
new UnsupportedFeatureWarning(
|
||||||
|
`\`webpackFetchPriority\` expected true or "low", "high" or "auto", but received: ${importOptions.webpackPreloadFetchPriority}.`,
|
||||||
|
/** @type {DependencyLocation} */ (expr.loc)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
preloadOptions.preloadOrder !== undefined &&
|
||||||
|
preloadOptions.preloadAs === undefined
|
||||||
|
) {
|
||||||
parser.state.module.addWarning(
|
parser.state.module.addWarning(
|
||||||
new CommentCompilationWarning(
|
new UnsupportedFeatureWarning(
|
||||||
`Compilation error while processing magic comment(-s): /*${comment.value}*/: ${e.message}`,
|
`\`webpackPreload\` for \`new URL(...)\` expected \`webpackPreloadAs\` comment.`,
|
||||||
comment.loc
|
/** @type {DependencyLocation} */ (expr.loc)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (importOptions) {
|
|
||||||
if (importOptions.webpackPreload !== undefined) {
|
|
||||||
if (importOptions.webpackPreload === true) {
|
|
||||||
preloadOptions.preloadOrder = 0;
|
|
||||||
} else if (typeof importOptions.webpackPreload === "number") {
|
|
||||||
preloadOptions.preloadOrder = importOptions.webpackPreload;
|
|
||||||
} else {
|
|
||||||
parser.state.module.addWarning(
|
|
||||||
new UnsupportedFeatureWarning(
|
|
||||||
`\`webpackPreload\` expected true or a number, but received: ${importOptions.webpackPreload}.`,
|
|
||||||
/** @type {DependencyLocation} */ (expr.loc)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (importOptions.webpackPreloadAs !== undefined) {
|
|
||||||
if (typeof importOptions.webpackPreloadAs === "string") {
|
|
||||||
preloadOptions.preloadAs = importOptions.webpackPreloadAs;
|
|
||||||
} else {
|
|
||||||
parser.state.module.addWarning(
|
|
||||||
new UnsupportedFeatureWarning(
|
|
||||||
`\`webpackPreloadAs\` expected string, but received: ${importOptions.webpackPreloadAs}.`,
|
|
||||||
/** @type {DependencyLocation} */ (expr.loc)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (importOptions.webpackFetchPriority !== undefined) {
|
|
||||||
if (
|
|
||||||
typeof importOptions.webpackFetchPriority === "string" &&
|
|
||||||
["high", "low", "auto"].includes(
|
|
||||||
importOptions.webpackFetchPriority
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
preloadOptions.fetchPriority =
|
|
||||||
importOptions.webpackFetchPriority;
|
|
||||||
} else {
|
|
||||||
parser.state.module.addWarning(
|
|
||||||
new UnsupportedFeatureWarning(
|
|
||||||
`\`webpackFetchPriority\` expected true or "low", "high" or "auto", but received: ${importOptions.webpackFetchPriority}.`,
|
|
||||||
/** @type {DependencyLocation} */ (expr.loc)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
preloadOptions.preloadOrder !== undefined &&
|
|
||||||
preloadOptions.preloadAs === undefined
|
|
||||||
) {
|
|
||||||
parser.state.module.addWarning(
|
|
||||||
new UnsupportedFeatureWarning(
|
|
||||||
`\`webpackPreload\` for \`new URL(...)\` expected \`webpackPreloadAs\` comment.`,
|
|
||||||
/** @type {DependencyLocation} */ (expr.loc)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO - `type` and `media` support
|
// TODO - `type` and `media` support
|
||||||
|
|
||||||
const [arg1, arg2] = expr.arguments;
|
const [arg1, arg2] = expr.arguments;
|
||||||
|
|
Loading…
Reference in New Issue