Skip to content

Commit

Permalink
fix passing publicPath to this.importModule
Browse files Browse the repository at this point in the history
  • Loading branch information
sokra committed Apr 14, 2021
1 parent 7ee3bab commit 8d3a230
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
7 changes: 6 additions & 1 deletion lib/dependencies/LoaderPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const LoaderImportDependency = require("./LoaderImportDependency");
/**
* @typedef {Object} ImportModuleOptions
* @property {string=} layer the target layer
* @property {string=} publicPath the target public path
*/

class LoaderPlugin {
Expand Down Expand Up @@ -199,7 +200,11 @@ class LoaderPlugin {
}
compilation.executeModule(
referencedModule,
{},
{
entryOptions: {
publicPath: options.publicPath
}
},
(err, result) => {
if (err) return callback(err);
for (const d of result.fileDependencies) {
Expand Down
2 changes: 1 addition & 1 deletion test/configCases/loader-import-module/css/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ it("should be able to use build-time code", () => {
'body { background: url("/public/assets/file.png?1"); color: #f00; }'
);
expect(otherStylesheet).toBe(
'body { background: url("/public/assets/file.jpg"); color: #0f0; }'
'body { background: url("/other/assets/file.jpg"); color: #0f0; }'
);
});
3 changes: 2 additions & 1 deletion test/configCases/loader-import-module/css/loader.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
exports.pitch = async function (remaining) {
const result = await this.importModule(
this.resourcePath + ".webpack[javascript/auto]" + "!=!" + remaining
this.resourcePath + ".webpack[javascript/auto]" + "!=!" + remaining,
this.getOptions()
);
return result.default || result;
};
18 changes: 15 additions & 3 deletions test/configCases/loader-import-module/css/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,21 @@ module.exports = {
},
rules: [
{
test: /stylesheet\.js$/,
use: "./loader",
type: "asset/source"
oneOf: [
{
test: /other-stylesheet\.js$/,
loader: "./loader",
options: {
publicPath: "/other/"
},
type: "asset/source"
},
{
test: /stylesheet\.js$/,
use: "./loader",
type: "asset/source"
}
]
},
{
test: /\.jpg$/,
Expand Down

0 comments on commit 8d3a230

Please sign in to comment.