李大仁 2019-07-01
效果如图所示:

index.html同级目录下添加favicon.ico文件
index.html中引入<link rel="shortcut icon" type="image/x-icon" href="./favicon.ico" />
webpack配置文件(build文件夹下面)在下面两个配置文件中加入:
favicon: path.resolve('./favicon.ico')具体位置:
webpack.prod.conf.js new HtmlWebpackPlugin({
filename: config.build.index,
template: 'index.html',
favicon: path.resolve('./favicon.ico'),
inject: true,
}),webpack.prod.dev.jsnew 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