@@ -13,8 +13,8 @@ const FAVICON_FILES = [
13
13
'favicon.webp' ,
14
14
] ;
15
15
16
- function getFaviconFile ( p : string ) : string | undefined {
17
- return FAVICON_FILES . find ( ( f ) => existsSync ( join ( p , f ) ) ) ;
16
+ function getFaviconFiles ( p : string ) : string [ ] | undefined {
17
+ return FAVICON_FILES . filter ( ( f ) => existsSync ( join ( p , f ) ) ) ;
18
18
}
19
19
20
20
export default ( api : IApi ) => {
@@ -26,39 +26,45 @@ export default (api: IApi) => {
26
26
27
27
api . modifyAppData ( async ( memo ) => {
28
28
if ( api . config . favicon ) return memo ;
29
- const faviconFile = getFaviconFile ( api . paths . absSrcPath ) ;
30
- if ( faviconFile ) {
31
- memo . faviconFile = faviconFile ;
29
+ const faviconFiles = getFaviconFiles ( api . paths . absSrcPath ) ;
30
+ if ( faviconFiles ) {
31
+ memo . faviconFiles = faviconFiles ;
32
32
}
33
33
return memo ;
34
34
} ) ;
35
35
36
36
api . addBeforeMiddlewares ( ( ) => [
37
37
( req , res , next ) => {
38
- if (
39
- api . appData . faviconFile &&
40
- req . path === `/${ api . appData . faviconFile } `
41
- ) {
42
- res . sendFile ( join ( api . paths . absSrcPath , api . appData . faviconFile ) ) ;
43
- } else {
38
+ const iconFile = ( api . appData . faviconFiles || [ ] ) . find (
39
+ ( file : any ) => req . path === `/${ file } ` ,
40
+ ) ;
41
+ if ( ! iconFile ) {
44
42
next ( ) ;
43
+ } else {
44
+ res . sendFile ( join ( api . paths . absSrcPath , iconFile ) ) ;
45
45
}
46
46
} ,
47
47
] ) ;
48
48
49
49
api . onBuildComplete ( ( { err } ) => {
50
50
if ( err ) return ;
51
- if ( api . appData . faviconFile ) {
52
- copyFileSync (
53
- join ( api . paths . absSrcPath , api . appData . faviconFile ) ,
54
- join ( api . paths . absOutputPath , api . appData . faviconFile ) ,
55
- ) ;
51
+ if ( api . appData . faviconFiles ) {
52
+ api . appData . faviconFiles . forEach ( ( e : any ) => {
53
+ copyFileSync (
54
+ join ( api . paths . absSrcPath , e ) ,
55
+ join ( api . paths . absOutputPath , e ) ,
56
+ ) ;
57
+ } ) ;
56
58
}
57
59
} ) ;
58
60
59
61
api . modifyHTMLFavicon ( ( memo ) => {
60
- return api . appData . faviconFile
61
- ? `${ api . config . publicPath } ${ api . appData . faviconFile } `
62
- : memo ;
62
+ // respect favicon config from user, and fallback to auto-detecting files
63
+ if ( ! memo . length && api . appData . faviconFiles ) {
64
+ api . appData . faviconFiles . forEach ( ( e : any ) => {
65
+ memo . push ( `${ api . config . publicPath } ${ e } ` ) ;
66
+ } ) ;
67
+ }
68
+ return memo ;
63
69
} ) ;
64
70
} ;
0 commit comments