Skip to content

Commit 8d3a230

Browse files
committed
fix passing publicPath to this.importModule
1 parent 7ee3bab commit 8d3a230

File tree

4 files changed

+24
-6
lines changed

4 files changed

+24
-6
lines changed

lib/dependencies/LoaderPlugin.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const LoaderImportDependency = require("./LoaderImportDependency");
3131
/**
3232
* @typedef {Object} ImportModuleOptions
3333
* @property {string=} layer the target layer
34+
* @property {string=} publicPath the target public path
3435
*/
3536

3637
class LoaderPlugin {
@@ -199,7 +200,11 @@ class LoaderPlugin {
199200
}
200201
compilation.executeModule(
201202
referencedModule,
202-
{},
203+
{
204+
entryOptions: {
205+
publicPath: options.publicPath
206+
}
207+
},
203208
(err, result) => {
204209
if (err) return callback(err);
205210
for (const d of result.fileDependencies) {

test/configCases/loader-import-module/css/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ it("should be able to use build-time code", () => {
1010
'body { background: url("/public/assets/file.png?1"); color: #f00; }'
1111
);
1212
expect(otherStylesheet).toBe(
13-
'body { background: url("/public/assets/file.jpg"); color: #0f0; }'
13+
'body { background: url("/other/assets/file.jpg"); color: #0f0; }'
1414
);
1515
});
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
exports.pitch = async function (remaining) {
22
const result = await this.importModule(
3-
this.resourcePath + ".webpack[javascript/auto]" + "!=!" + remaining
3+
this.resourcePath + ".webpack[javascript/auto]" + "!=!" + remaining,
4+
this.getOptions()
45
);
56
return result.default || result;
67
};

test/configCases/loader-import-module/css/webpack.config.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,21 @@ module.exports = {
1616
},
1717
rules: [
1818
{
19-
test: /stylesheet\.js$/,
20-
use: "./loader",
21-
type: "asset/source"
19+
oneOf: [
20+
{
21+
test: /other-stylesheet\.js$/,
22+
loader: "./loader",
23+
options: {
24+
publicPath: "/other/"
25+
},
26+
type: "asset/source"
27+
},
28+
{
29+
test: /stylesheet\.js$/,
30+
use: "./loader",
31+
type: "asset/source"
32+
}
33+
]
2234
},
2335
{
2436
test: /\.jpg$/,

0 commit comments

Comments
 (0)