1 通过.umirc.ts配置
1.1 UMI 1.X
1 | links: [{ rel: 'icon', href: '/img/favicon.ico' }] |
1.2 UMI 2.X
没有相关配置项。
1.3 UMI 3.X
1 | favicon: '/assets/favicon.ico', |
2. 通过document.ejs配置
这个方法对所有版本的UMI都通用。
2.1 添加src/pages/document.ejs
UMI约定如果这个文件存在,就会作为默认模板。例如:
01 02 03 04 05 06 07 08 09 10 | <! doctype html> < html > < head > < meta charset = "utf-8" /> < title >Your App</ title > </ head > < body > < div id = "root" ></ div > </ body > </ html > |
在<head/>标签中,添加一行:
1 | < link rel = "icon" type = "image/x-icon" href="<%= context.publicPath %>favicon.png" /> |
publicPath,默认值是‘/’,指可以通过‘域名/’访问public文件夹里的静态资源(例如图片,css等)。可以在.umirc.ts里进行配置,本例中没有配置,用的默认值。
2.2 添加favicon.png
在UMI项目跟目录创建一个folder,命名为‘public’,然后把favicon.png放进public folder。
