Skip to content

Commit f8ad5c9

Browse files
committed
fix: issue by HMR when CSS contains Tailwind-like style names with backslashes
1 parent 5c0d5ed commit f8ad5c9

File tree

8 files changed

+27
-5
lines changed

8 files changed

+27
-5
lines changed

CHANGELOG.md

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

3+
## 4.5.3 (2024-11-28)
4+
5+
- fix: issue by HMR when CSS contains Tailwind-like style names with backslashes
6+
E.g.: `.\32xl\:w-96`, `.lg\:ml-4`
7+
38
## 4.5.2 (2024-11-28)
49

510
- fix: issue by HMR when CSS contains a comment with `back-tick` quotes

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": "4.5.2",
3+
"version": "4.5.3",
44
"description": "HTML Bundler Plugin for Webpack renders HTML templates containing source files of scripts, styles, images. Supports template engines: Eta, EJS, Handlebars, Nunjucks, Pug, TwigJS. Alternative to html-webpack-plugin.",
55
"keywords": [
66
"html",

src/Loader/cssLoader.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,10 @@ const pitchLoader = async function (remaining) {
8181

8282
if (isHmr) {
8383
let css = result.default.toString();
84-
const search = /\n|`/g;
84+
const search = /\n|\\|`/g;
8585
const replacements = {
8686
'\n': '',
87+
'\\': '\\\\',
8788
'`': '\\`',
8889
};
8990

test/cases/option-css-hot-dev/expected/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<title>Home</title>
55
</head>
66
<body>
7-
<h1>Home</h1>
7+
<h1 class="2xl:w-96 lg:ml-4">Home</h1>
88
<script src="main.js"></script>
99
</body>
1010
</html>

test/cases/option-css-hot-dev/expected/main.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
/* module decorator */ module = __webpack_require__.nmd(module);
1111
/* extracted by HTMLBundler CSSLoader */
12-
const css = `/* Comment with \`back-tick\` quotes */h1 { color: violet;}`;
12+
const css = `/* Comment with \`back-tick\` quotes */h1 { color: violet; text-align: center; border: 2px solid coral;}/* Test ERROR: Module parse failed: Bad escape sequence in untagged template literal. The problem is with Tailwind-like style names: \`.\\32xl\\:w-96\`. */.\\32 xl\\:w-96 { width: 10rem;}.lg\\:ml-4 { margin-left: 1rem;}`;
1313
const isDocument = typeof document !== 'undefined';
1414

1515
function hotUpdateCSS(css) {
@@ -138,6 +138,7 @@ __webpack_require__.r(__webpack_exports__);
138138
/* harmony import */ var _style_css__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./style.css */ "./src/style.css");
139139
/* harmony import */ var _style_css__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_style_css__WEBPACK_IMPORTED_MODULE_0__);
140140

141+
//import './tailwind.css';
141142

142143
console.log('>> main.js');
143144

test/cases/option-css-hot-dev/src/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<title>Home</title>
55
</head>
66
<body>
7-
<h1>Home</h1>
7+
<h1 class="2xl:w-96 lg:ml-4">Home</h1>
88
<script src="./main.js"></script>
99
</body>
1010
</html>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
import './style.css';
2+
//import './tailwind.css';
23

34
console.log('>> main.js');

test/cases/option-css-hot-dev/src/style.css

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,18 @@
22

33
h1 {
44
color: violet;
5+
text-align: center;
6+
border: 2px solid coral;
7+
}
8+
9+
/*
10+
Test ERROR: Module parse failed: Bad escape sequence in untagged template literal.
11+
The problem is with Tailwind-like style names: `.\32xl\:w-96`.
12+
*/
13+
.\32xl\:w-96 {
14+
width: 10rem;
15+
}
16+
17+
.lg\:ml-4 {
18+
margin-left: 1rem;
519
}

0 commit comments

Comments
 (0)