File tree Expand file tree Collapse file tree 7 files changed +60
-14
lines changed
crates/rspack_plugin_html/src
packages/rspack-test-tools/tests/configCases/builtins
html-favicon-absolute-publicpath-auto
html-favicon-relative-publicpath-auto Expand file tree Collapse file tree 7 files changed +60
-14
lines changed Original file line number Diff line number Diff line change @@ -111,21 +111,17 @@ impl HtmlPluginAssets {
111111 favicon_relative_path. to_string_lossy ( ) . to_string ( ) . as_str ( ) ,
112112 ) ) ;
113113
114- let fake_html_file_name = compilation
115- . get_path (
116- html_file_name,
117- PathData :: default ( ) . filename ( output_path. as_str ( ) ) ,
118- )
119- . always_ok ( ) ;
120-
121114 if favicon_path. to_str ( ) . unwrap_or_default ( ) . is_empty ( ) {
122- favicon_path = compilation
123- . options
124- . output
125- . path
126- . as_std_path ( )
127- . join ( favicon_relative_path)
128- . relative ( PathBuf :: from ( fake_html_file_name) . join ( ".." ) ) ;
115+ let fake_html_file_name = compilation
116+ . get_path (
117+ html_file_name,
118+ PathData :: default ( ) . filename ( output_path. as_str ( ) ) ,
119+ )
120+ . always_ok ( ) ;
121+ let output_path = compilation. options . output . path . as_std_path ( ) ;
122+ favicon_path = output_path
123+ . relative ( output_path. join ( fake_html_file_name) . join ( ".." ) )
124+ . join ( favicon_relative_path) ;
129125 } else {
130126 favicon_path. push ( favicon_relative_path) ;
131127 }
Original file line number Diff line number Diff line change 1+ const fs = require ( "fs" ) ;
2+ const path = require ( "path" ) ;
3+
4+ it ( "html favicon with absolute path and public path" , ( ) => {
5+ const faviconPath = path . join ( __dirname , "./favicon.ico" ) ;
6+ expect ( fs . existsSync ( faviconPath ) ) . toBe ( true ) ;
7+
8+ const htmlPath = path . join ( __dirname , "./index.html" ) ;
9+ const htmlContent = fs . readFileSync ( htmlPath , "utf-8" ) ;
10+ expect ( htmlContent ) . toContain ( '<link href="favicon.ico" rel="icon">' ) ;
11+ } ) ;
Original file line number Diff line number Diff line change 1+ const path = require ( "path" ) ;
2+ const { rspack } = require ( "@rspack/core" ) ;
3+
4+ /** @type {import("@rspack/core").Configuration } */
5+ module . exports = {
6+ output : {
7+ publicPath : "auto" ,
8+ } ,
9+ plugins : [
10+ new rspack . HtmlRspackPlugin ( {
11+ favicon : path . resolve ( __dirname , "favicon.ico" )
12+ } )
13+ ]
14+ } ;
Original file line number Diff line number Diff line change 1+ const fs = require ( "fs" ) ;
2+ const path = require ( "path" ) ;
3+
4+ it ( "html favicon with absolute path and public path" , ( ) => {
5+ const faviconPath = path . join ( __dirname , "./favicon.ico" ) ;
6+ expect ( fs . existsSync ( faviconPath ) ) . toBe ( true ) ;
7+
8+ const htmlPath = path . join ( __dirname , "./index.html" ) ;
9+ const htmlContent = fs . readFileSync ( htmlPath , "utf-8" ) ;
10+ expect ( htmlContent ) . toContain ( '<link href="favicon.ico" rel="icon">' ) ;
11+ } ) ;
Original file line number Diff line number Diff line change 1+ const path = require ( "path" ) ;
2+ const { rspack } = require ( "@rspack/core" ) ;
3+
4+ /** @type {import("@rspack/core").Configuration } */
5+ module . exports = {
6+ output : {
7+ publicPath : "auto" ,
8+ } ,
9+ plugins : [
10+ new rspack . HtmlRspackPlugin ( {
11+ favicon : "favicon.ico"
12+ } )
13+ ]
14+ } ;
You can’t perform that action at this time.
0 commit comments