【webpack】webpack的html-webpack-plugin中的title不起作用?(已解决)

解决Webpack中html-webpack-plugin配置title无效问题
在Webpack配置中使用html-webpack-plugin时,仅设置title选项并不足以更新HTML文件的title标签。需要在index.html中引入htmlWebpackPlugin.options.title变量来动态插入标题。正确做法是在HTML模板中添加<title><%=%>htmlWebpackPlugin.options.title</title>,这样才能使Webpack构建时自动更新页面标题。

只是在webpack中的html-webpack-plugin中配置title是不起作用的

new HtmlWebpackPlugin({
    title: 'React Common Backstage',
    template: path.resolve(__dirname, 'public/index.html')
})

还需要在index.html文件中引入变量

<title><%= htmlWebpackPlugin.options.title %></title>

现在就可以咯。
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值