效果如圖所示:
index.html
同級目錄下添加favicon.ico
文件
index.html
中引入<link rel="shortcut icon" type="image/x-icon" href="./favicon.ico" />
webpack
配置文件(build文件夾下面)在下面兩個配置文件中加入:javascript
favicon: path.resolve('./favicon.ico')
具體位置:html
webpack.prod.conf.js
new HtmlWebpackPlugin({ filename: config.build.index, template: 'index.html', favicon: path.resolve('./favicon.ico'), inject: true, }),
webpack.prod.dev.js
new HtmlWebpackPlugin({ filename: process.env.NODE_ENV === 'testing' ? 'index.html' : config.build.index, template: 'index.html', favicon: path.resolve('./favicon.ico'), inject: true, minify: { removeComments: true, collapseWhitespace: true, removeAttributeQuotes: true // more options: // https://github.com/kangax/html-minifier#options-quick-reference }
npm run dev