基于此葬礼: using html-webpack-plugin to generate index.html 如果您向html-webpack-plugin选项添加 title 选项,如下所示:
new HtmlWebPackPlugin({
template: './src/index.html',
filename: './index.html',
title: 'My App',
}),
并将以下代码段添加到您的HTML模板
<title><%= htmlWebpackPlugin.options.title %></title>
它应该从插件设置中获取标题值,并将其显示在标题标签内。
但是似乎<%= htmlWebpackPlugin.options.title %>
并没有获得价值!可能是Webpack 4中不推荐使用此功能吗?
答案 0 :(得分:1)
我从webpack.config.js中删除了html-loader。 然后,它就像一个魅力 问候
答案 1 :(得分:0)
@ user1941537
安装以下依赖项:
npm install -D --safe-dev ejs-loader extract-loader
并按如下所示为.html文件添加规则,
rules:[{
test: /\.html$/,
use: ['ejs-loader', 'extract-loader', 'html-loader']
}]