Skip to content

Commit

Permalink
fix: error by resolving url() in the CSS file defined in the entry op…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
webdiscus committed Jan 22, 2024
1 parent 40983d1 commit bc12d1f
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change log

## 3.4.11 (2024-01-22)

- fix: error by resolving url() in the CSS file defined in the entry option

## 3.4.10 (2024-01-16)

- fix: save the webmanifest files in the directory defined in the `faviconOptions.path` option
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": "3.4.10",
"version": "3.4.11",
"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.",
"keywords": [
"html",
Expand Down
3 changes: 3 additions & 0 deletions src/Plugin/Collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,9 @@ class Collection {
* @param {CollectionData|{}} data The collection data.
*/
static setData(entry, issuer, data = {}) {
// skip when the resource is defined in the entry option, not in the entry template
if (!entry) return;

const { filename } = entry;
const entryPoint = this.data.get(filename);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.apple {
width: 160px;
height: 130px;
background-image: url(../img/apple.02a7c382.png);
border: 5px solid orangered;
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions test/cases/resolve-url-in-css-entry/src/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.apple {
width: 160px;
height: 130px;
background-image: url('@images/apple.png');
border: 5px solid orangered;
}
46 changes: 46 additions & 0 deletions test/cases/resolve-url-in-css-entry/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const path = require('path');
const HtmlBundlerPlugin = require('@test/html-bundler-webpack-plugin');

module.exports = {
mode: 'production',

output: {
path: path.join(__dirname, 'dist/'),
},

resolve: {
alias: {
'@images': path.join(__dirname, '../../fixtures/images'),
},
},

entry: {
// test: resolve url() in css defined in entry option, not in entry template
style: './src/style.css',
},

plugins: [
new HtmlBundlerPlugin({
css: {
filename: 'css/[name].[contenthash:8].css',
},
}),
],

module: {
rules: [
{
test: /\.(css)$/,
loader: 'css-loader',
},

{
test: /\.(png|jpe?g|ico)$/,
type: 'asset/resource',
generator: {
filename: 'img/[name].[hash:8][ext]',
},
},
],
},
};
3 changes: 3 additions & 0 deletions test/integration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ describe('resolve styles', () => {
});

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

0 comments on commit bc12d1f

Please sign in to comment.