vue-cli3 multiple-pages 多页面打包实践

4,701 阅读1分钟

实现

1、添加模版文件

在 public 文件夹里添加模版文件

如:/public/demo.html

模版文件也可以直接放置在pages下的文件夹里

如:src/pages/demo2/demo2.html

使用 vue-cli3 的 pages

2、创建 vue.config.js 文件

3、配置 pages 字段

  module.exports = {
    pages: {
      index: {
        entry: 'src/main.js',  // page 的入口
        template: 'public/index.html', // 模板来源
        filename: 'index.html', //  在 dist/index.html 的输出
      },
      demo: {
        entry: 'src/pages/demo/main.js',
        template: 'public/demo.html',
        filename: 'demo.html',
      },
      demo2: {
        entry: 'src/pages/demo2/main.js',
        template: 'src/pages/demo2/demo2.html',
        filename: 'demo2.html',
      },
    }
  }

具体配置可以参考 vue-cli官方文档

4、在src下创建文件夹

src/pages/demo

src/pages/demo2

每个分包配置自己单独的路由和入口文件

5、本地开发和访问

npm run serve

http://localhost:8080/demo

http://localhost:8080/test

http://localhost:8080/demo2

6、现有业务迁移

在pages文件夹下建立views文件夹 ,相关业务直接迁移即可 当然具体项目具体处理,有的路由有变化的在细节自己把控和修改即可

结果及数据支持

暂无

其他

源码