vue版本  3.4.1

Vue CLI生成的脚手架的html模板文件,public/index.html

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <link rel="icon" href="<%= BASE_URL %>favicon.ico">
    <title><%= htmlWebpackPlugin.options.title %></title>
    <script type="text/javascript" src="//api.map.baidu.com/api?type=webgl&v=1.0&ak=vLAvtufMmPdf1LyyDSgrimpyd22jRVsb"></script>
    <link rel="stylesheet" href="<%= BASE_URL %>css/font-awesome.min.css">
  </head>
  <body>
    <noscript>
      <strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
    </noscript>
    <div id="app"></div>
    <!-- built files will be auto injected -->
  </body>
</html>

可以看到public/index.html模板中的title属性是一个webpack的配置项,vue-cli的配置参考中,有提到如何修改模板中的title配置。就是pages配置项。

module.exports = {
  pages: {
    index: {
      // page 的入口
      entry: 'src/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']
    }
  }
}

要注意入口文件和模板文件的路径是否正确。

 

Logo

前往低代码交流专区

更多推荐