vue.js添加favicon图标的方法:1、修改【index.html】文件,代码为【
缺点:打包后需要将
favicon.ico复制到根目录方法二:修改webpack配置文件
1、找到build下的webpack.dev.conf.js文件
new HtmlWebpackPlugin({ filename: 'index.html', template: 'index.html', inject: true, favicon: path.resolve('favicon.ico') // 新增 }),2、找到build下的webpack.prod.conf.js文件
new HtmlWebpackPlugin({ filename: config.build.index, template: 'index.html', inject: true, favicon: path.resolve('favicon.ico'), //新增 minify: { emoveComments: true, collapseWhitespace: true, removeAttributeQuotes: true ... }),方法三 :vue项目打包后favicon无法正常显示
解决方法:
在webpack.prod.config.js中的HtmlWebpackPlugin插件选项中配置favicon选项,其中favicon的路径是个相对路径
new HtmlWebpackPlugin({ filename: 'index.html', template: 'index.html', favicon: 'src/assets/img/favicon.ico', inject: true }),修改配置文件后需重启
npm run dev打包后根目录下就会有favicon.ico