Skip to content

Commit 0b8e670

Browse files
committed
fix: output.publicPath ignored for FaviconsBundlerPlugin, #156
1 parent a7ad609 commit 0b8e670

32 files changed

Lines changed: 219 additions & 13 deletions

CHANGELOG.md

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

3+
## 4.18.1 release (2025-03-13)
4+
5+
- fix: output.publicPath ignored for FaviconsBundlerPlugin, #156
6+
37
## 4.18.0 release (2025-02-03)
48

59
- chore: bump the version for release

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "html-bundler-webpack-plugin",
3-
"version": "4.18.0",
3+
"version": "4.18.1",
44
"description": "Generates complete single-page or multi-page website from source assets. Build-in support for Markdown, Eta, EJS, Handlebars, Nunjucks, Pug. Alternative to html-webpack-plugin.",
55
"keywords": [
66
"html",
@@ -146,7 +146,7 @@
146146
},
147147
"dependencies": {
148148
"@types/html-minifier-terser": "^7.0.2",
149-
"ansis": "3.9.0",
149+
"ansis": "3.17.0",
150150
"enhanced-resolve": ">=5.7.0",
151151
"eta": "^3.5.0",
152152
"html-minifier-terser": "^7.2.0"

plugins/favicons-bundler-plugin/index.js

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,21 @@ class FaviconsBundlerPlugin {
1515
/** {string} The source favicon file. */
1616
faviconFile = '';
1717

18+
/**
19+
* The output path to save generated files.
20+
*
21+
* @type {string}
22+
* */
23+
outputPath = '';
24+
25+
/**
26+
* The full output public path..
27+
* It will be used if Webpack output.publicPath ia a URL.
28+
*
29+
* @type {string}
30+
* */
31+
outputUrl = '';
32+
1833
/**
1934
* The key is the source HTML file, where was found the original `faviconFile` parsed in the `faviconTag`.
2035
* The `faviconFile` is the source file of the parsed favicon file.
@@ -31,11 +46,18 @@ class FaviconsBundlerPlugin {
3146
this.options = options;
3247
// favicons configuration options, see https://github.com/itgalaxy/favicons#usage
3348
this.options.faviconsConfig = { ...config.defaults, ...(options.faviconOptions || {}) };
49+
this.outputPath = this.options.faviconsConfig?.path ?? '';
3450
}
3551

3652
apply(compiler) {
3753
const bundlerPluginOption = PluginService.getPluginContext(compiler).pluginOption;
3854
const enabled = bundlerPluginOption.toBool(this.options?.enabled, true, 'auto');
55+
const isUrlPublicPath = bundlerPluginOption.isUrlPublicPath();
56+
57+
if (isUrlPublicPath) {
58+
let publicPath = bundlerPluginOption.getPublicPath();
59+
this.outputUrl = new URL(this.outputPath, publicPath).href;
60+
}
3961

4062
if (!enabled) {
4163
return;
@@ -90,6 +112,7 @@ class FaviconsBundlerPlugin {
90112
// save favicon manifest files on disk
91113
response.files.forEach(({ name, contents }) => {
92114
let outputFile = path.posix.join(this.options.faviconsConfig.path, name);
115+
93116
compilation.emitAsset(outputFile, new RawSource(contents));
94117
});
95118
});
@@ -102,7 +125,15 @@ class FaviconsBundlerPlugin {
102125
const page = this.pages.get(info.sourceFile);
103126

104127
if (page && this.faviconResponse) {
105-
content = content.replace(page.faviconTag, this.faviconResponse.html);
128+
let { outputUrl, outputPath } = this;
129+
let faviconHtml = this.faviconResponse.html;
130+
131+
if (outputUrl) {
132+
faviconHtml = faviconHtml.replaceAll(outputPath, outputUrl);
133+
}
134+
135+
// inject generated <link> tags
136+
content = content.replace(page.faviconTag, faviconHtml);
106137
}
107138

108139
return content;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<!DOCTYPE html><html><head><script src="js/file1.034defc3.js"></script><script src="js/file2.e5c7f644.js"></script><script src="js/file3.f1b372d2.js"></script><script src="js/file4.daa27ac4.js"></script><script src="js/file5.c863871f.js"></script><script src="js/cli.242bd8e6.js"></script><script src="js/index.1222a4ca.js"></script></head><body><h1>Hello World!</h1></body></html>
1+
<!DOCTYPE html><html><head><script src="js/file1.034defc3.js"></script><script src="js/file2.e5c7f644.js"></script><script src="js/file3.f1b372d2.js"></script><script src="js/file4.daa27ac4.js"></script><script src="js/file5.c863871f.js"></script><script src="js/cli.a2b3651f.js"></script><script src="js/index.0e40943e.js"></script></head><body><h1>Hello World!</h1></body></html>

test/cases/_pug/require-script-tags/expected/js/cli.242bd8e6.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/cases/_pug/require-script-tags/expected/js/cli.a2b3651f.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/cases/_pug/require-script-tags/expected/js/index.0e40943e.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/cases/_pug/require-script-tags/expected/js/index.1222a4ca.js

Lines changed: 0 additions & 1 deletion
This file was deleted.
30.2 KB
Loading

0 commit comments

Comments
 (0)