Skip to content

Commit

Permalink
fix: issue by HMR when CSS contains Tailwind-like style names with ba…
Browse files Browse the repository at this point in the history
…ckslashes
  • Loading branch information
webdiscus committed Nov 28, 2024
1 parent 5c0d5ed commit f8ad5c9
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 5 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Change log

## 4.5.3 (2024-11-28)

- fix: issue by HMR when CSS contains Tailwind-like style names with backslashes
E.g.: `.\32xl\:w-96`, `.lg\:ml-4`

## 4.5.2 (2024-11-28)

- fix: issue by HMR when CSS contains a comment with `back-tick` quotes
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "html-bundler-webpack-plugin",
"version": "4.5.2",
"version": "4.5.3",
"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.",
"keywords": [
"html",
Expand Down
3 changes: 2 additions & 1 deletion src/Loader/cssLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,10 @@ const pitchLoader = async function (remaining) {

if (isHmr) {
let css = result.default.toString();
const search = /\n|`/g;
const search = /\n|\\|`/g;
const replacements = {
'\n': '',
'\\': '\\\\',
'`': '\\`',
};

Expand Down
2 changes: 1 addition & 1 deletion test/cases/option-css-hot-dev/expected/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<title>Home</title>
</head>
<body>
<h1>Home</h1>
<h1 class="2xl:w-96 lg:ml-4">Home</h1>
<script src="main.js"></script>
</body>
</html>
3 changes: 2 additions & 1 deletion test/cases/option-css-hot-dev/expected/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

/* module decorator */ module = __webpack_require__.nmd(module);
/* extracted by HTMLBundler CSSLoader */
const css = `/* Comment with \`back-tick\` quotes */h1 { color: violet;}`;
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;}`;
const isDocument = typeof document !== 'undefined';

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

//import './tailwind.css';

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

Expand Down
2 changes: 1 addition & 1 deletion test/cases/option-css-hot-dev/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<title>Home</title>
</head>
<body>
<h1>Home</h1>
<h1 class="2xl:w-96 lg:ml-4">Home</h1>
<script src="./main.js"></script>
</body>
</html>
1 change: 1 addition & 0 deletions test/cases/option-css-hot-dev/src/main.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import './style.css';
//import './tailwind.css';

console.log('>> main.js');
14 changes: 14 additions & 0 deletions test/cases/option-css-hot-dev/src/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,18 @@

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`.
*/
.\32xl\:w-96 {
width: 10rem;
}

.lg\:ml-4 {
margin-left: 1rem;
}

0 comments on commit f8ad5c9

Please sign in to comment.