vue怎样修改标题 <%= htmlWebpackPlugin.options.title %>

这么改报错。

// vue.config.js
module.exports = {
    configureWebpack: config => {
        config.devtool ='source-map';
        config
            .plugin('html')
            .tap(args => {
                args[0].title= 'test'
                return args
            })
    }
}
 ERROR  TypeError: config.plugin is not a function
TypeError: config.plugin is not a function
    at configureWebpack (D:\wgf\My Documents\Github\pyprojects\ups_project\client\vue.config.js:6:14)
    at D:\wgf\My Documents\Github\pyprojects\ups_project\client\node_modules\@vue\cli-service\lib\Service.js:266:21
    at Array.forEach (<anonymous>)
    at Service.resolveWebpackConfig (D:\wgf\My Documents\Github\pyprojects\ups_project\client\node_modules\@vue\cli-service\lib\Service.js:263:30)
    at PluginAPI.resolveWebpackConfig (D:\wgf\My Documents\Github\pyprojects\ups_project\client\node_modules\@vue\cli-service\lib\PluginAPI.js:132:25)
    at serve (D:\wgf\My Documents\Github\pyprojects\ups_project\client\node_modules\@vue\cli-service\lib\commands\serve.js:74:31)
    at Service.run (D:\wgf\My Documents\Github\pyprojects\ups_project\client\node_modules\@vue\cli-service\lib\Service.js:245:12)
    at Object.<anonymous> (D:\wgf\My Documents\Github\pyprojects\ups_project\client\node_modules\@vue\cli-service\bin\vue-cli-service.js:36:9)
    at Module._compile (internal/modules/cjs/loader.js:1176:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1196:10)
    at Module.load (internal/modules/cjs/loader.js:1040:32)
    at Function.Module._load (internal/modules/cjs/loader.js:929:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
    at internal/main/run_main_module.js:17:47
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! del1@0.1.0 serve: `vue-cli-service serve`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the del1@0.1.0 serve script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     D:\wgf\AppData\Roaming\npm-cache\_logs\2020-05-28T06_54_26_317Z-debug.log

Process finished with exit code 1
阅读 33.6k
6 个回答

chainWebpack

在main.js 可以动态设置标题
image.png

是name属性把

  pages: {
    index: {
      // page 的入口
      entry: 'src/index/main.js',
      // 模板来源
      template: 'public/index.html',
      // 在 dist/index.html 的输出
      filename: 'index.html',
      // 当使用 title 选项时,
      // template 中的 title 标签需要是 <title><%= htmlWebpackPlugin.options.title %></title>
      title: 'Index Page',
      // 在这个页面中包含的块,默认情况下会包含
      // 提取出来的通用 chunk 和 vendor chunk。
      chunks: ['chunk-vendors', 'chunk-common', 'index']
    },
    // 当使用只有入口的字符串格式时,
    // 模板会被推导为 `public/subpage.html`
    // 并且如果找不到的话,就回退到 `public/index.html`。
    // 输出文件名会被推导为 `subpage.html`。
    subpage: 'src/subpage/main.js'
  }
新手上路,请多包涵

写在 chainWebpack 里面就可以了

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题