- 在項目根目錄下的 index.html 文件的title 標簽中添加標題欄文字
- 將圖片文件favicon.ico 放在項目根目錄下
- 修改 build 文件夾下 webpack.dev.conf.js 和 webpack.prod.conf.js 文件的配置
// HtmlWebpackPlugin 中添加 favicon
// path為引入的模塊const path = require('path')
webpack.dev.conf.js文件:
new HtmlWebpackPlugin({
filename: 'index.html',
template: 'index.html',
inject: true,
favicon: path.resolve('favicon.ico') //添加該行
})
webpack.prod.conf.js文件:
new HtmlWebpackPlugin({
filename: process.env.NODE_ENV === 'testing' ? 'index.html' : config.build.index,
template: 'index.html',
inject: true,
favicon: path.resolve('favicon.ico') //添加該行
minify: {
removeComments: true,
collapseWhitespace: true,
removeAttributeQuotes: true
// more options:
// https://github.com/kangax/html-minifier#options-quick-reference
},
// necessary to consistently work with multiple chunks via CommonsChunkPlugin
chunksSortMode: 'dependency'
})
- 重啟項目即可