diff --git a/src/loader.js b/src/loader.js index 8a387946..fb51cbba 100644 --- a/src/loader.js +++ b/src/loader.js @@ -361,7 +361,7 @@ function pitch(request) { } this.importModule( - `${this.resourcePath}.webpack[javascript/auto]!=!!!${request}`, + `${this._module.matchResource || this.resourcePath}.webpack[javascript/auto]!=!!!${request}`, { layer: options.layer, publicPath: /** @type {string} */ (publicPathForExtract), diff --git a/test/cases/match-resource-url/expected/main.css b/test/cases/match-resource-url/expected/main.css new file mode 100644 index 00000000..35a7a05d --- /dev/null +++ b/test/cases/match-resource-url/expected/main.css @@ -0,0 +1,4 @@ +body { + background-image: url(static/icon.svg); +} + diff --git a/test/cases/match-resource-url/icon.svg b/test/cases/match-resource-url/icon.svg new file mode 100644 index 00000000..3b4bcabe --- /dev/null +++ b/test/cases/match-resource-url/icon.svg @@ -0,0 +1 @@ + diff --git a/test/cases/match-resource-url/index.js b/test/cases/match-resource-url/index.js new file mode 100644 index 00000000..0bb9d665 --- /dev/null +++ b/test/cases/match-resource-url/index.js @@ -0,0 +1 @@ +import "./virtual.css!=!./source.txt"; diff --git a/test/cases/match-resource-url/source.txt b/test/cases/match-resource-url/source.txt new file mode 100644 index 00000000..8f8d8336 --- /dev/null +++ b/test/cases/match-resource-url/source.txt @@ -0,0 +1,3 @@ +body { + background-image: url(./icon.svg); +} diff --git a/test/cases/match-resource-url/test.filter.js b/test/cases/match-resource-url/test.filter.js new file mode 100644 index 00000000..ffca14d7 --- /dev/null +++ b/test/cases/match-resource-url/test.filter.js @@ -0,0 +1,3 @@ +import yn from "../../helpers/yn"; + +module.exports = () => !yn(process.env.OLD_API); diff --git a/test/cases/match-resource-url/webpack.config.js b/test/cases/match-resource-url/webpack.config.js new file mode 100644 index 00000000..c9cc91c2 --- /dev/null +++ b/test/cases/match-resource-url/webpack.config.js @@ -0,0 +1,26 @@ +import Self from "../../../src"; + +module.exports = { + entry: "./index.js", + module: { + rules: [ + { + test: /\.css$/, + use: [Self.loader, "css-loader"], + }, + { + test: /\.svg$/, + issuer: /\.css$/, + type: "asset/resource", + generator: { + filename: "static/[name][ext]", + }, + }, + ], + }, + plugins: [ + new Self({ + filename: "[name].css", + }), + ], +};