@@ -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 ;
0 commit comments