我正在使用 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
检查了webpack配置产生以下输出
/* 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'
}
)
Web 应用程序的标题仍然是“Vue App”。
有什么想法吗?
PS:我不想设置document.title = 'Custom Title'
我的应用程序中的某处。我想要 <title>
之间的标题- <head>
中的标签要在构建时更改的文档元素。
最佳答案
不幸的是,上述答案对我没有帮助。
如前所述in the offical documentation您只需将 vue.config.js
添加到根文件夹并添加以下内容:
// vue.config.js
module.exports = {
chainWebpack: config => {
config
.plugin('html')
.tap(args => {
args[0].title = 'Your new title'
return args
})
}
}
请记住,您必须停止应用程序并使用 npm runserve
重新启动。这对我有用。
关于vue.js - Vue-Cli : 'title' option for htmlWebpackPlugin does not work,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54951082/