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 runtime generation bug #16903

Merged
merged 6 commits into from Apr 19, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
4 changes: 1 addition & 3 deletions lib/dependencies/CssUrlDependency.js
Expand Up @@ -108,7 +108,7 @@ CssUrlDependency.Template = class CssUrlDependencyTemplate extends (
apply(
dependency,
source,
{ runtime, moduleGraph, runtimeTemplate, codeGenerationResults }
{ moduleGraph, runtimeTemplate, codeGenerationResults }
) {
const dep = /** @type {CssUrlDependency} */ (dependency);

Expand All @@ -119,7 +119,6 @@ CssUrlDependency.Template = class CssUrlDependencyTemplate extends (
newValue = cssEscapeString(
runtimeTemplate.assetUrl({
publicPath: "",
runtime,
module: moduleGraph.getModule(dep),
codeGenerationResults
})
Expand All @@ -129,7 +128,6 @@ CssUrlDependency.Template = class CssUrlDependencyTemplate extends (
newValue = `url(${cssEscapeString(
runtimeTemplate.assetUrl({
publicPath: "",
runtime,
module: moduleGraph.getModule(dep),
codeGenerationResults
})
Expand Down
2 changes: 2 additions & 0 deletions test/configCases/css/runtimeissue/asyncChunk.js
@@ -0,0 +1,2 @@
import * as style from "./styles.js";
export default style;
2 changes: 2 additions & 0 deletions test/configCases/css/runtimeissue/asyncChunk2.js
@@ -0,0 +1,2 @@
import * as style from "./styles.js";
export default style;
14 changes: 14 additions & 0 deletions test/configCases/css/runtimeissue/entry1.js
@@ -0,0 +1,14 @@
const img = new URL("./img.png", import.meta.url);
janlent1 marked this conversation as resolved.
Show resolved Hide resolved

it("should allow to create css modules", done => {
import("./asyncChunk").then(({ default: x }) => {
try {
expect(img.toString()).toBe("https://test.cases/path/img.png");
expect(x.default.class).toEqual("./test.module.css-class");
} catch (e) {
return done(e);
}

done();
}, done);
});
14 changes: 14 additions & 0 deletions test/configCases/css/runtimeissue/entry2.js
@@ -0,0 +1,14 @@
const img = new URL("./img.png", import.meta.url);

it("should allow to create css modules", done => {
import("./asyncChunk2").then(({ default: x }) => {
try {
expect(img.toString()).toBe("https://test.cases/path/img.png");
expect(x.default.class).toEqual("./test.module.css-class");
} catch (e) {
return done(e);
}

done();
}, done);
});
Binary file added test/configCases/css/runtimeissue/img.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions test/configCases/css/runtimeissue/share.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions test/configCases/css/runtimeissue/styles.js
@@ -0,0 +1,2 @@
import * as style from "./test.module.css";
export default style;
21 changes: 21 additions & 0 deletions test/configCases/css/runtimeissue/test.config.js
@@ -0,0 +1,21 @@
module.exports = {
moduleScope(scope) {
janlent1 marked this conversation as resolved.
Show resolved Hide resolved
const link1 = scope.window.document.createElement("link");
link1.rel = "stylesheet";
link1.href = "asyncChunk_js.css";
scope.window.document.head.appendChild(link1);
const link2 = scope.window.document.createElement("link");
link2.rel = "stylesheet";
link2.href = "asyncChunk_js2.css";
scope.window.document.head.appendChild(link2);
},
findBundle: function (i, options) {
return [
"./common-share_js-img_png.js",
"./asyncChunk_js.js",
"./main.js",
"./secondMain.js",
"./asyncChunk2_js.js"
];
}
};
3 changes: 3 additions & 0 deletions test/configCases/css/runtimeissue/test.module.css
@@ -0,0 +1,3 @@
.class {
background-image: url('./img.png');
}
5 changes: 5 additions & 0 deletions test/configCases/css/runtimeissue/use-style.js
@@ -0,0 +1,5 @@
import * as style from "./test.module.css";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need this file now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If not, I can remove it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexander-akait I removed the file


export default {
item: style.item
};
34 changes: 34 additions & 0 deletions test/configCases/css/runtimeissue/webpack.config.js
@@ -0,0 +1,34 @@
/** @type {import("../../../../").Configuration} */
module.exports = {
target: "web",
mode: "development",
experiments: {
css: true
},
entry: {
main: {
import: ["./share.js", "./entry1.js"]
},
secondMain: {
import: ["./share.js", "./entry2.js"]
}
},
optimization: {
splitChunks: {
chunks: "all",
cacheGroups: {
common: {
name: false,
chunks: "all",
test() {
return true;
}
}
}
}
},
output: {
filename: "[name].js",
assetModuleFilename: "[name][ext]"
}
};