Ehan Van的博客
首页
前端笔记
首页
前端笔记
  • 前端笔记

    • v-on的使用
    • 编写一个Vue递归组件
    • 非vue文件中申明的ref如何使用
    • Vue3如何在hook中执行异步函数并同步返回响应式数据
    • 如何终止forEach循环
    • 递归创建下拉树数据
    • 编写一个Vue Web Components
    • js数组toString的使用
    • vueconfig配置多page遇到的坑
    • js事件循环机制
    • React列表渲染中图片闪烁问题
    • 开发中未配置Referrer遇到的坑
    • 前端实现文件分片上传
    • 防抖函数
    • 编写一个vue插件
    • 发布订阅模式

业务场景

一个系统需要使用不同html文件作为入口,实现多页面,如:index.html、index2.html、index3.html等,使用vue-cli4搭建项目,配置vue.config.js实现多页面。

遇到的坑

按照官网给的配置进行复制,结果发现两个页面完全一样

图片

错误配置如下

module.exports = {
  transpileDependencies: true,
  pages: {
    index: {
      entry: "src/index/main.js",
      template: "public/index.html",
      filename: "index.html",
      title: "Index",
      chunks: ["chunk-vendors", "chunk-common", "index"],
    },
    index2: {
      entry: "src/index2/main.js",
      template: "public/index2.html",
      filename: "index2.html",
      title: "Index2 Index2 Index2",
      chunks: ["chunk-vendors", "chunk-common", "index"],
    },
  },
};

解决方法

问题出在index2的chunks上,注释掉index2的chunks重新运行项目,页面就没问题了

module.exports = {
  transpileDependencies: true,
  pages: {
    index: {
      entry: "src/index/main.js",
      template: "public/index.html",
      filename: "index.html",
      title: "Index",
      chunks: ["chunk-vendors", "chunk-common", "index"],
    },
    index2: {
      entry: "src/index2/main.js",
      template: "public/index2.html",
      filename: "index2.html",
      title: "Index2 Index2 Index2",
    },
  },
};

效果

图片

Prev
js数组toString的使用
Next
js事件循环机制