在项目的index.html 中引入图片:
<head>
<title>标题</title>
<link rel="icon" href="./favicon.ico" type="image/x-icon">
</head>
其中,favicon.ico图片在项目根目录下。接着就是修改 build 文件夹下 webpack.prod.conf.js 和 webpack.dev.conf.js 文件。
webpack.prod.conf.js文件夹修改如下:
new HtmlWebpackPlugin({
filename: process.env.NODE_ENV === 'testing'
? 'index.html'
: config.build.index,
template: 'index.html',
favicon: path.resolve('favicon.ico'), // 引入图片地址
inject: true,
webpack.dev.conf.js文件夹修改如下:
new HtmlWebpackPlugin({
filename: 'index.html',
template: 'index.html',
favicon: path.resolve('favicon.ico'), // 引入图片地址
inject: true
}),
注意,以上文件均需引入path 模块。
var path = require('path') // 开头引入 path 模块
然后重新启动项目即可。