Skip to content

Commit 795bd06

Browse files
committed
fix: output.publicPath ignored for FaviconsBundlerPlugin, #156
1 parent 2de9dd8 commit 795bd06

28 files changed

Lines changed: 210 additions & 2 deletions

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ Consider `generator.dataUrl()` and `generator.dataUrl.encoding` Webpack options.
5555
- fix: the output SVG should contain the changes made in generator.dataUrl()
5656
- docs: add information about preload priority to readme
5757

58+
## 4.18.1 release (2025-03-13)
59+
60+
- fix: output.publicPath ignored for FaviconsBundlerPlugin, #156
61+
5862
## 4.18.0 release (2025-02-03)
5963

6064
- chore: bump the version for release

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.4d9f628c.js"></script><script src="js/index.4b79462d.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.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.
30.2 KB
Loading
49.8 KB
Loading
27.5 KB
Loading
3.1 KB
Loading
155 KB
Loading

0 commit comments

Comments
 (0)