webpack:4 打包多入口

  1. 入口
entry: {
    // 前台
    index: './public/assets/js/index',  //打包入口项
    list: './public/assets/js/list',
    search: './public/assets/js/search',
    detail: './public/assets/js/detail',
    jquery: './public/assets/vendors/jquery/jquery.min.js',
    // 后台
  },
  1. 出口
  output: {
    path: path.join(__dirname, './dist'),
    filename: '[name].bundle.js',  //多入口写法--打包出同名文件
  },
  1. 对应的插件
plugins: [
    //后台
    //前台
    new Webpack.ProvidePlugin({
      $: 'jquery'  //全局暴露的第三方库      .不写内置模块的话,报$ is not defined
    }),
    new HtmlWebpackPlugin({
      filename: 'index.html',
      template: path.join(__dirname, './public/index.html'),
      chunks: ['index']          //多入口写法--按需导入
    }),
    new HtmlWebpackPlugin({
      filename: 'list.html',
      template: path.join(__dirname, './public/list.html'),
      chunks: ['list']
    }),
    new HtmlWebpackPlugin({
      filename: 'search.html',
      template: path.join(__dirname, './public/search.html'),
      chunks: ['search']
    }),
    new HtmlWebpackPlugin({
      filename: 'detail.html',
      template: path.join(__dirname, './public/detail.html'),
      chunks: ['detail']
    })
  ],
  1. 完整截图

webpack:4 打包多入口_第1张图片
webpack:4 打包多入口_第2张图片

你可能感兴趣的:(webpack)