我正在使用 vue-cli (3.4.1),我只是想简单地更改文档的标题。
我将以下内容添加到 vue.config.js
chainWebpack: (config) => {
config
.plugin('html')
.tap((args) => {
args[0].title = 'Custom Title';
return args;
});
},
并使用 vue inspect --plugin html
产生以下输出
/* config.plugin('html') */
new HtmlWebpackPlugin(
{
templateParameters: function () { /* omitted long function */ },
template: '<path>\node_modules\\@vue\\cli-service\\lib\\config\\index-default.html',
title: 'Custom Title'
}
)
Webapp 的标题仍然是“Vue App”。
任何想法为什么?
PS:我不想在我的应用程序的某个地方设置 document.title = 'Custom Title'
。我想要在构建时更改文档的 <head>
元素中的 <title>
标签之间的标题。
原文由 Kristof Komlossy 发布,翻译遵循 CC BY-SA 4.0 许可协议
我按照@tony19 的建议提交了错误报告。
tldnr:编辑模板中的标题
public/index.html
将在构建时使用。长版本:我的项目中不再有
public/index.html
,显然我前段时间删除了它,因此从未使用过模板功能。 cli 仍然使用位于某处的模板,因此对 htmlWebpackPlugin 的所有更改都没有任何作用。因此,要么禁用 index.html 模板并修改 htmlWebpackPlugin,要么编辑模板以进行更改。