Skip to content

Commit 9503a7f

Browse files
fix(css): minify assets with fragment suffixes
1 parent d7237bf commit 9503a7f

4 files changed

Lines changed: 12 additions & 1 deletion

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"webpack": patch
3+
---
4+
5+
Minify CSS assets whose names include fragment suffixes.

‎lib/css/cssMinify.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,6 @@ cssMinify.getEmbeddedTypes = () => [
173173
* @param {string} name asset filename
174174
* @returns {boolean} true for CSS assets
175175
*/
176-
cssMinify.filter = (name) => /\.css(\?.*)?$/i.test(name);
176+
cssMinify.filter = (name) => /\.css(?:[?#].*)?$/i.test(name);
177177

178178
module.exports = cssMinify;

‎test/configCases/css/minimize-experiments-true/test.config.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ module.exports = {
2020
// Emitted by another plugin and unclaimed, so the built-in minifier takes
2121
// it too — a copied stylesheet still gets minimized.
2222
expect(read("copied.css")).toBe(".copied{color:red}");
23+
expect(read("fragment.css")).toBe(".fragment{color:red}");
2324

2425
// Already marked `minimized`, so a minimizer the user configured has
2526
// handled it — webpack must leave it exactly as it was.

‎test/configCases/css/minimize-experiments-true/webpack.config.js‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ class EmitOtherCssAssetsPlugin {
3131
"copied.css",
3232
new sources.RawSource(".copied {\n\tcolor : red ;\n}\n")
3333
);
34+
// A legacy plugin may still assign an asset directly. The output filesystem
35+
// strips the fragment, but the minimizer sees this original name first.
36+
compilation.assets["fragment.css#dark"] = new sources.RawSource(
37+
".fragment {\n\tcolor : red ;\n}\n"
38+
);
3439
compilation.emitAsset(
3540
"already.css",
3641
new sources.RawSource(".already {\n\tcolor : red ;\n}\n"),

0 commit comments

Comments
 (0)