Skip to content

Commit bc12d1f

Browse files
committed
fix: error by resolving url() in the CSS file defined in the entry option
1 parent 40983d1 commit bc12d1f

8 files changed

Lines changed: 69 additions & 1 deletion

File tree

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.11 (2024-01-22)
4+
5+
- fix: error by resolving url() in the CSS file defined in the entry option
6+
37
## 3.4.10 (2024-01-16)
48

59
- fix: save the webmanifest files in the directory defined in the `faviconOptions.path` option

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.10",
3+
"version": "3.4.11",
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/Collection.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,9 @@ class Collection {
672672
* @param {CollectionData|{}} data The collection data.
673673
*/
674674
static setData(entry, issuer, data = {}) {
675+
// skip when the resource is defined in the entry option, not in the entry template
676+
if (!entry) return;
677+
675678
const { filename } = entry;
676679
const entryPoint = this.data.get(filename);
677680

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.apple {
2+
width: 160px;
3+
height: 130px;
4+
background-image: url(../img/apple.02a7c382.png);
5+
border: 5px solid orangered;
6+
}
1.74 KB
Loading
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.apple {
2+
width: 160px;
3+
height: 130px;
4+
background-image: url('@images/apple.png');
5+
border: 5px solid orangered;
6+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
const path = require('path');
2+
const HtmlBundlerPlugin = require('@test/html-bundler-webpack-plugin');
3+
4+
module.exports = {
5+
mode: 'production',
6+
7+
output: {
8+
path: path.join(__dirname, 'dist/'),
9+
},
10+
11+
resolve: {
12+
alias: {
13+
'@images': path.join(__dirname, '../../fixtures/images'),
14+
},
15+
},
16+
17+
entry: {
18+
// test: resolve url() in css defined in entry option, not in entry template
19+
style: './src/style.css',
20+
},
21+
22+
plugins: [
23+
new HtmlBundlerPlugin({
24+
css: {
25+
filename: 'css/[name].[contenthash:8].css',
26+
},
27+
}),
28+
],
29+
30+
module: {
31+
rules: [
32+
{
33+
test: /\.(css)$/,
34+
loader: 'css-loader',
35+
},
36+
37+
{
38+
test: /\.(png|jpe?g|ico)$/,
39+
type: 'asset/resource',
40+
generator: {
41+
filename: 'img/[name].[hash:8][ext]',
42+
},
43+
},
44+
],
45+
},
46+
};

test/integration.test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ describe('resolve styles', () => {
3939
});
4040

4141
describe('resolve url() in style', () => {
42+
// TODO: fix not working
43+
// background: url("@icons/arrow.png") no-repeat center center / auto 100%;
4244
test('url(image) in CSS', () => compareFiles('resolve-url-in-css'));
45+
test('url(image) in CSS entry', () => compareFiles('resolve-url-in-css-entry'));
4346
test('CSS imported in module with .css', () => compareFiles('import-css-from-module-with-ext'));
4447
test('CSS imported from module without .css', () => compareFiles('import-css-from-module-wo-ext'));
4548
test('@import url() in CSS', () => compareFiles('import-url-in-css'));

0 commit comments

Comments
 (0)