Method one: Modify index.html file
<link rel="shortcut icon" type="image/x-icon" href="favicon.ico"/>
Cons: After the package needs to be copied to the root directory favicon.ico
Method Two: Modify webpack profile
1, found under the Build webpack.dev.conf.js file
new HtmlWebpackPlugin({
filename: 'index.html',
template: 'index.html',
inject: true,
favicon: path.resolve('favicon.ico') // 新增
}),
2, found under the Build webpack.prod.conf.js file
new HtmlWebpackPlugin({
filename: config.build.index,
template: 'index.html',
inject: true,
favicon: path.resolve('favicon.ico'), //新增
minify: {
removeComments: true,
collapseWhitespace: true,
removeAttributeQuotes: true
...
}),
After modifying the configuration file you need to restart npm run dev
after packing will be favicon.ico in the root directory