Skip to content

Commit faa2e9e

Browse files
committed
fix: error by resolving url(date:image...) in CSS
1 parent f2635a7 commit faa2e9e

25 files changed

Lines changed: 270 additions & 2 deletions

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Change log
22

3+
## 3.4.8 (2024-01-15)
4+
5+
- fix: error by resolving `url(date:image...)` in CSS
6+
37
## 3.4.7 (2024-01-09)
48

59
- fix: if the same CSS file is imported in many js files, then the CSS is extracted for the first issuer only, #68

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.7",
3+
"version": "3.4.8",
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/Utils.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,14 @@ const transformToCommonJS = (code) => {
1010
for (const [match, variable, file] of importMatches) {
1111
code = code.replace(match, `var ${variable} = require('${file}');`);
1212
}
13-
// new URL to require
13+
14+
// transform `new URL("data:image...", import.meta.url)` to 'data:image...'
15+
const urlDataMatches = code.matchAll(/= new URL\("(data:.+?)", import.meta.url\);/g);
16+
for (const [match, data] of urlDataMatches) {
17+
code = code.replace(match, `= '${data}';`);
18+
}
19+
20+
// transform `new URL("file")` to `require('file')`
1421
const urlMatches = code.matchAll(/= new URL\("(.+?)".*?\);/g);
1522
for (const [match, file] of urlMatches) {
1623
code = code.replace(match, `= require('${file}');`);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Test</title>
5+
<link href="main.bundle.css" rel="stylesheet">
6+
<script src="main.bundle.js" defer="defer"></script>
7+
</head>
8+
<body>
9+
<h1>Hello World!</h1>
10+
</body>
11+
</html>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
h1 {
2+
color: red;
3+
}
4+
h1 {
5+
color: green;
6+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(()=>{"use strict";console.log(">> main")})();
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Test</title>
5+
<script src="./main.js" defer="defer"></script>
6+
</head>
7+
<body>
8+
<h1>Hello World!</h1>
9+
</body>
10+
</html>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import './style1.css';
2+
import './style2.css';
3+
4+
console.log('>> main');
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
h1 {
2+
color: red;
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
h1 {
2+
color: green;
3+
}

0 commit comments

Comments
 (0)