美文网首页
Vue创建多页面应用

Vue创建多页面应用

作者: 寻找无名的特质 | 来源:发表于2022-10-29 06:35 被阅读0次

使用webpack模板创建项目vue init webpack multi-entry-vue
1、在目录下创建新的入口文件main2.js,这个文件引用不同的组件比如App2.vue
2、进入 \build\webpack.base.conf.js 目录下,在module.exports的域里,找到entry,在那里配置添加多个入口

module.exports = {
  context: path.resolve(__dirname, '../'),
  entry: {
    app: './src/main.js',
    app2: './src/main2.js'
  },

3、进入\build\webpack.dev.config.js,修改开发时的入口:

    new HtmlWebpackPlugin({
      filename: 'index.html',
      template: 'index.html',
      inject: true,
      chunks:['app']  //增加
    }),
    //增加
    new HtmlWebpackPlugin({
      filename: 'index2.html',
      template: 'index.html',
      inject: true,
      chunks:['app2']
    }),

4、进入\build\webpack.prod.config.js,修改开发时的入口:

 new HtmlWebpackPlugin({
      filename: config.build.index,
      template: 'index.html',
      inject: true,
      minify: {
        removeComments: true,
        collapseWhitespace: true,
        removeAttributeQuotes: true
        // more options:
        // https://github.com/kangax/html-minifier#options-quick-reference
      },
      // necessary to consistently work with multiple chunks via CommonsChunkPlugin
      chunksSortMode: 'dependency',
      chunks:['manifest','vendor','app'] //增加
    }),
//增加
    new HtmlWebpackPlugin({
      filename: "index2.html",
      template: 'index.html',
      inject: true,
      minify: {
        removeComments: true,
        collapseWhitespace: true,
        removeAttributeQuotes: true
        // more options:
        // https://github.com/kangax/html-minifier#options-quick-reference
      },
      // necessary to consistently work with multiple chunks via CommonsChunkPlugin
      //chunksSortMode: 'dependency'
      chunks:['manifest','vendor','app2']
    }),

5、一般情况下,使用相同的Index.html作为起始页模板是可以的,不一样的话,还需要在config/index.js中增加模板定义。
build: {
// Template for index.html
index: path.resolve(__dirname, '../dist/index.html'),

相关文章

  • Vue创建多页面应用

    使用webpack模板创建项目vue init webpack multi-entry-vue1、在目录下创建新的...

  • Vue CLI3开发多页面应用

    简要说明 使用vue脚手架创建的vue项目均为单页面应用。但是有时候我们也需要多页面应用,那该如何使用cli来配置...

  • Vue.js 搭建多页应用

    Vue.js 搭建多页应用 参考vue2.0之多页面的开发 创建项目 仿照index.html,App.vue,m...

  • 基于vue-cli搭建一个多页面应用

    上篇文章中,我们已经成功使用yarn创建了一个vue项目,但是项目模板是单页面应用,与多页面应用还有些差别,所以现...

  • vue多页应用

    vue如何将单页面改造成多页面应用 vue单页多页的开发环境配置+vue的开发思路

  • 基于vue多入口项目升级webpack4实践

    项目背景简介 多页面应用,每个页面独立entry,单个页面内使用vue-router 基于vue,使用vue-lo...

  • 使用webpack配置多页面应用

    多页面应用 说到多页面应用,我们先来熟悉一下相反的单页面应用,提起单页面应用大家一定不会陌生,像vue、react...

  • (22)打鸡儿教你Vue.js

    vue.js 单页面,多页面 Vue cli工具复杂单页面应用Vue cli工具 交互设计,逻辑设计,接口设计 代...

  • Vue-router 懒加载 - 异步组件

    当在使用 vue-router 来构建一个 vue 单页面应用的时候,如果应用的路有页面非常多的时候,应用打包后 ...

  • vue多页应用配置

    vue脚手架创建的项目都是单页面应用但是有一些场景下我们需要使用多页面应用(比如一个系统的后端和前端要分为不同的页...

网友评论

      本文标题:Vue创建多页面应用

      本文链接:https://www.haomeiwen.com/subject/osgxtdtx.html