Skip to content

Commit f2635a7

Browse files
committed
fix: if the same CSS file is imported in many js files, then the CSS is extracted for the first issuer only, #68
1 parent b7e2f37 commit f2635a7

20 files changed

Lines changed: 185 additions & 4 deletions

CHANGELOG.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
# Change log
22

3+
## 3.4.7 (2024-01-09)
4+
5+
- fix: if the same CSS file is imported in many js files, then the CSS is extracted for the first issuer only, #68
6+
37
## 3.4.6 (2024-01-02)
48

5-
fix: the `pathData.chunk.name` is undefined when the `js.filename` is a function, this bug was introduced in `3.4.5`
9+
- fix: the `pathData.chunk.name` is undefined when the `js.filename` is a function, this bug was introduced in `3.4.5`
610

711
## 3.4.5 (2024-01-01)
812

9-
fix: the `pathData.filename` is undefined after changes when the `js.filename` is a function
13+
- fix: the `pathData.filename` is undefined after changes when the `js.filename` is a function
1014

1115
## 3.4.4 (2023-12-28)
1216

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "html-bundler-webpack-plugin",
3-
"version": "3.4.6",
3+
"version": "3.4.7",
44
"description": "HTML bundler plugin for webpack handles a template as an entry point, extracts CSS and JS from their sources referenced in HTML, supports template engines like Eta, EJS, Handlebars, Nunjucks.",
55
"keywords": [
66
"html",

src/Plugin/AssetCompiler.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1001,7 +1001,20 @@ class AssetCompiler {
10011001
const orderedRootIssuers = Collection.orderedResources.get(entry.id);
10021002

10031003
for (const issuer of orderedRootIssuers) {
1004-
if (!Collection.importStyleRootIssuers.has(issuer)) continue;
1004+
// Fix #68: if the same `c.css` file was imported in many js files: `a.js` and `b.js`,
1005+
// then webpack processes the css module only for 1st `a.js`, others issuers will be ignored,
1006+
// then we lost relation: a.js -> c.css (ok) but b.js -> c.css (lost).
1007+
// So we can't use the following check for avoid unnecessary searching in js files where no CSS has been imported
1008+
// Side-effect: increases build time for cases when many js files do not import css.
1009+
// TODO: create a cache for js files that don't import CSS.
1010+
// if (!Collection.importStyleRootIssuers.has(issuer)) {
1011+
// console.log('--- importStyleRootIssuers: ', {
1012+
// entryFilename,
1013+
// issuer,
1014+
// importStyleRootIssuers: Collection.importStyleRootIssuers,
1015+
// });
1016+
// continue;
1017+
// }
10051018

10061019
const issuerEntry = AssetEntry.getByResource(issuer);
10071020
const sources = [];
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.bar {
2+
color: dodgerblue;
3+
background-color: white;
4+
border: 1px solid dodgerblue;
5+
}
6+
.foo {
7+
color: red;
8+
background-color: white;
9+
border: 1px solid red;
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.bar {
2+
color: dodgerblue;
3+
background-color: white;
4+
border: 1px solid dodgerblue;
5+
}
6+
.foo {
7+
color: red;
8+
background-color: white;
9+
border: 1px solid red;
10+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(()=>{"use strict";console.log(">> Page A: ",{Foo:"Component Bar",Bar:"Component Foo"})})();
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(()=>{"use strict";console.log(">> Page B: ",{Foo:"Component Bar",Bar:"Component Foo"})})();
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Page A</title>
5+
<link href="css/pageA.5b01e96e.css" rel="stylesheet">
6+
</head>
7+
<body>
8+
<div style="display: flex; flex-direction: column;">
9+
<h1>Page A</h1>
10+
<a href="pageB.html">Visit Page B</a>
11+
<b>Styled components:</b>
12+
<div class="bar">Foo</div>
13+
<div class="foo">Bar</div>
14+
</div>
15+
<script src="js/pageA.2fcc41eb.js"></script>
16+
</body>
17+
</html>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Page B</title>
5+
<link href="css/pageB.b78f128d.css" rel="stylesheet">
6+
</head>
7+
<body>
8+
<div style="display: flex; flex-direction: column;">
9+
<h1>Page B</h1>
10+
<a href="pageA.html">Visit Page A</a>
11+
<b>Styled components:</b>
12+
<div class="bar">Foo</div>
13+
<div class="foo">Bar</div>
14+
</div>
15+
<script src="js/pageB.af02ad73.js"></script>
16+
</body>
17+
</html>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.bar {
2+
color: dodgerblue;
3+
background-color: white;
4+
border: 1px solid dodgerblue;
5+
}

0 commit comments

Comments
 (0)