vue.js - Vue-Cli : 'title' option for htmlWebpackPlugin does not work

标签 vue.js webpack vue-cli-3

我正在使用 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/

相关文章:

vue.js - 缺少依赖项: aws-sdk in ./node_modules/node-pre-gyp/lib/info.js

javascript - Vue 组件版本控制,这样的事情可能吗?

node.js - Webpack 失败,babel 已移至 babel-core

javascript - 从 vue-cli 3 : Adding script tags to App. vue 将 Vuetify 添加到项目模板会破坏应用程序吗?

vue.js - Vue-cli 3 - Material 设计图标安装

vue.js - 在 vue-cli 3 项目中使用带有 npm-link 的 vuex store 丢失 $store

javascript - Vue 路由器 + Vuex : how to make beforeEach route guard wait for Vuex state change?

javascript - 无法在vue单文件组件中循环数组

reactjs - "Missing class properties transform",即使安装了相关的 Babel 插件后

javascript - Uncaught ReferenceError : $ is not defined Webpack and embedded script