Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: oneOf rule has been picked multiple times #16477

Merged
merged 1 commit into from Apr 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/NormalModuleFactory.js
Expand Up @@ -509,6 +509,11 @@ class NormalModuleFactory extends ModuleFactory {
issuerLayer: contextInfo.issuerLayer || ""
});
for (const r of result) {
// https://github.com/webpack/webpack/issues/16466
// if a request exists PrePostAutoLoaders, should disable modifying Rule.type
if (r.type === "type" && noPrePostAutoLoaders) {
continue;
}
if (r.type === "use") {
if (!noAutoLoaders && !noPrePostAutoLoaders) {
useLoaders.push(r.value);
Expand Down
4 changes: 4 additions & 0 deletions test/configCases/rule-set/oneOf/css-loader.js
@@ -0,0 +1,4 @@
/** @type {import("../../../../").LoaderDefinition<{ get(): string }>} */
module.exports = function (source) {
return "module.exports='__css__'"
}
3 changes: 3 additions & 0 deletions test/configCases/rule-set/oneOf/index.css
@@ -0,0 +1,3 @@
body {
color: red;
}
4 changes: 4 additions & 0 deletions test/configCases/rule-set/oneOf/index.js
@@ -0,0 +1,4 @@
it("should return the content processed by css-loader instead of asset/resource", function () {
var a1 = require("./index.css");
expect(a1).toEqual("__css__");
});
16 changes: 16 additions & 0 deletions test/configCases/rule-set/oneOf/style-loader.js
@@ -0,0 +1,16 @@
/** @type {import("../../../../types").LoaderDefinition<{ get(): string }>} */
module.exports.pitch = function (request) {
return `
var content = require(${stringifyRequest(this, `!!${request}`)});
module.exports = content;
`
};

function stringifyRequest(loaderContext, request) {
return JSON.stringify(
loaderContext.utils.contextify(
loaderContext.context || loaderContext.rootContext,
request
)
)
}
24 changes: 24 additions & 0 deletions test/configCases/rule-set/oneOf/webpack.config.js
@@ -0,0 +1,24 @@
/** @type {import("../../../../").Configuration} */
module.exports = {
mode: "development",
output: {
assetModuleFilename: "[name][ext]"
},
module: {
rules: [
{
test: /\.css$/,
oneOf: [
{
use: ["./style-loader", "./css-loader"],
issuer: /\.(js)$/
},
{
type: "asset/resource",
issuer: /\.(css|scss|sass)$/
}
]
}
]
}
};