美文网首页
8 多页面应用打包

8 多页面应用打包

作者: 辣瓜瓜 | 来源:发表于2019-12-22 22:35 被阅读0次

多页面应用打包

  1. webpack.config.js中修改入口和出口配置
  // 1. 修改为多入口
  entry: {
      main: './src/main.js',
      other: './src/other.js'
  },
  output: {
    path: path.join(__dirname, './dist/'),
    // filename: 'bundle.js',
    // 2. 多入口无法对应一个固定的出口, 所以修改filename为[name]变量
    filename: '[name].bundle.js',
    publicPath: '/'
  },
  plugins: [
      // 3. 如果用了html插件,需要手动配置多入口对应的html文件,将指定其对应的输出文件
      new HtmlWebpackPlugin({
          template: './index.html',
          filename: 'index.html',
          chunks: ['main']
      }),
      new HtmlWebpackPlugin({
          template: './index.html',
          filename: 'other.html',
          // chunks: ['other', 'main']
          chunks: ['other']
      })
  ]

修改入口为对象,支持多个js入口,同时修改output输出的文件名为'[name].js'表示各自已入口文件名作为输出文件名,但是html-webpack-plugin不支持此功能,所以需要再拷贝一份插件,用于生成两个html页面,实现多页应用.

相关文章

  • 8 多页面应用打包

    多页面应用打包 在webpack.config.js中修改入口和出口配置 修改入口为对象,支持多个js入口,同时修...

  • 12、打包多页面应用

    1、需下载依赖: ① npm init -y 初始化包 ② npm i webpack webpack-cli -...

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

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

  • webpack4.0 watch

    1.打包多页应用 多个entry打包多个页面为例 首先output的filename中,用变量name打包不同的j...

  • 多页面打包配置

    之前我们打包,实际上都是对单页面应用进行的打包 什么叫做单页面应用呢? 整个应用里边只有一个html文件,就是单页...

  • webpack配置多页面

    配置打包多页面

  • Vue、React前端项目打包部署

    前端单页面应用部署 前端打包上线部署方案之 hash路由模式 对于hash路由模式打包的单页面应用,直接发布到服务...

  • webpack多页面应用打包通用方案

    多页面应用(MPA)概念 每次页面跳转的时候,后台服务器都会返回一个新的html文档,这种类型的网站也就是多页网站...

  • CRA多入口集成

    前言 新生的CRA配置是单页面网页应用 出于某些目的,需要打包成多入口。比如storybook框架,多入口使用if...

  • webpack 代码分割的两种方式

    1. 多入口打包 适用于传统的多页应用程序,一个页面对应一个打包入口,公告部分单独提取 1.1 提取公共模块 ...

网友评论

      本文标题:8 多页面应用打包

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