const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin') // 清空打包目录的插件
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const webpack = require('webpack');
const proxyHost = "http://192.168.2.241:6060";
module.exports = {
  entry: {
    //index: path.resolve(__dirname, 'src/js', 'index.js'),
    //information: path.resolve(__dirname, 'src/js', 'information.js'),
    informationOut: path.resolve(__dirname, 'src/js', 'informationOut.js'),
    disclaimer: path.resolve(__dirname, 'src/js', 'disclaimer.js'),
    version: path.resolve(__dirname, 'src/js', 'version.js'),
    scale: path.resolve(__dirname, 'src/js', 'scale.js'),
    //staticSearch: path.resolve(__dirname, 'src/js', 'staticSearch.js'),
    emergency: path.resolve(__dirname, 'src/js', 'emergency.js'),
    cdss: path.resolve(__dirname, 'src/js', 'cdss.js'),
    cdssHorizontal: path.resolve(__dirname, 'src/js', 'cdssHorizontal.js'),
    smartAlert: path.resolve(__dirname, 'src/js', 'smartAlert.js'),
    caseWriteStandard: path.resolve(__dirname, 'src/js', 'caseWriteStandard.js'),
    generalTreat:path.resolve(__dirname, 'src/js', 'generalTreat.js'),
    cdssPlan:path.resolve(__dirname, 'src/js', 'cdssPlan.js'),
    homeStatic:path.resolve(__dirname, 'src/js', 'homeStatic.js'),
    searchStaticList:path.resolve(__dirname, 'src/js', 'searchStaticList.js'),
    staticInfo:path.resolve(__dirname, 'src/js', 'staticInfo.js'),
    //staticInfoOut:path.resolve(__dirname, 'src/js', 'informationOut.js'),
    vendor: 'lodash'// 多个页面所需的公共库文件，防止重复打包带入
  },
  output: {
    publicPath: '/', //这里要放的是静态资源CDN的地址
    path: path.resolve(__dirname, 'dist'),
    filename: 'js/[name].js'
  },
  resolve: {
    extensions: [".js", ".css", ".json"],
    alias: {} //配置别名可以加快webpack查找模块的速度
  },
  plugins: [// 多入口的html文件用chunks这个参数来区分
    new HtmlWebpackPlugin({
      title: 'homeStatic',
      template: path.resolve(__dirname, 'src/html', 'homeStatic.html'),
      filename: 'homeStatic.html',
      chunks: ['homeStatic', 'vendor', 'common'],
      inject: true,
      hash: true, //防止缓存
      minify: {
        removeAttributeQuotes: true, //压缩 去掉引号
        removeComments: true, //移除HTML中的注释
        collapseWhitespace: true //删除空白符与换行符
      }
    }),
    new HtmlWebpackPlugin({
      title: 'staticInfo',
      template: path.resolve(__dirname, 'src/html', 'staticInfo.html'),
      filename: 'staticInfo.html',
      chunks: ['staticInfo', 'vendor', 'common'],
      inject: true,
      hash: true, //防止缓存
      minify: {
        removeAttributeQuotes: true, //压缩 去掉引号
        removeComments: true, //移除HTML中的注释
        collapseWhitespace: true //删除空白符与换行符
      }
    }),
    new HtmlWebpackPlugin({
      title: 'searchStaticList',
      template: path.resolve(__dirname, 'src/html', 'searchStaticList.html'),
      filename: 'searchStaticList.html',
      chunks: ['searchStaticList', 'vendor', 'common'],
      inject: true,
      hash: true, //防止缓存
      minify: {
        removeAttributeQuotes: true, //压缩 去掉引号
        removeComments: true, //移除HTML中的注释
        collapseWhitespace: true //删除空白符与换行符
      }
    }),
    new HtmlWebpackPlugin({
      title: '智能警示',
      template: path.resolve(__dirname, 'src/html', 'smartAlert.html'),
      filename: 'smartAlert.html',
      chunks: ['smartAlert', 'vendor', 'common'],
      inject: true,
      hash: true, //防止缓存
      minify: {
        removeAttributeQuotes: true, //压缩 去掉引号
        removeComments: true, //移除HTML中的注释
        collapseWhitespace: true //删除空白符与换行符
      }
    }),
    new HtmlWebpackPlugin({
      title: '随访计划',
      template: path.resolve(__dirname, 'src/html', 'cdssPlan.html'),
      filename: 'cdssPlan.html',
      chunks: ['cdssPlan', 'vendor', 'common'],
      inject: true,
      hash: true, //防止缓存
      minify: {
        removeAttributeQuotes: true, //压缩 去掉引号
        removeComments: true, //移除HTML中的注释
        collapseWhitespace: true //删除空白符与换行符
      }
    }),
    new HtmlWebpackPlugin({
      title: '病历书写规范提示',
      template: path.resolve(__dirname, 'src/html', 'caseWriteStandard.html'),
      filename: 'caseWriteStandard.html',
      chunks: ['caseWriteStandard', 'vendor', 'common'],
      inject: true,
      hash: true, //防止缓存
      minify: {
        removeAttributeQuotes: true, //压缩 去掉引号
        removeComments: true, //移除HTML中的注释
        collapseWhitespace: true //删除空白符与换行符
      }
    }),
    new HtmlWebpackPlugin({
      title: '一般治疗',
      template: path.resolve(__dirname, 'src/html', 'generalTreat.html'),
      filename: 'generalTreat.html',
      chunks: ['generalTreat', 'vendor', 'common'],
      inject: true,
      hash: true, //防止缓存
      minify: {
        removeAttributeQuotes: true, //压缩 去掉引号
        removeComments: true, //移除HTML中的注释
        collapseWhitespace: true //删除空白符与换行符
      }
    }),
    /*new HtmlWebpackPlugin({
      title: 'information',
      template: path.resolve(__dirname, 'src/html', 'information.html'),
      filename: 'information.html',
      chunks: ['information', 'vendor', 'common'],
      inject: true,
      hash: true, //防止缓存
      minify: {
        removeAttributeQuotes: true, //压缩 去掉引号
        removeComments: true, //移除HTML中的注释
        collapseWhitespace: true //删除空白符与换行符
      }
    }),*/
    new HtmlWebpackPlugin({
      title: 'informationOut',
      template: path.resolve(__dirname, 'src/html', 'informationOut.html'),
      filename: 'informationOut.html',
      chunks: ['informationOut', 'vendor', 'common'],
      inject: true,
      hash: true, //防止缓存
      minify: {
        removeAttributeQuotes: true, //压缩 去掉引号
        removeComments: true, //移除HTML中的注释
        collapseWhitespace: true //删除空白符与换行符
      }
    }),
    new HtmlWebpackPlugin({
      title: '免责声明',
      template: path.resolve(__dirname, 'src/html', 'disclaimer.html'),
      filename: 'disclaimer.html',
      chunks: ['vendor', 'common', 'disclaimer'],
      inject: true,
      hash: true, //防止缓存
      minify: {
        removeAttributeQuotes: true, //压缩 去掉引号
        removeComments: true, //移除HTML中的注释
        collapseWhitespace: true //删除空白符与换行符
      }
    }),
    new HtmlWebpackPlugin({
      title: '版本信息',
      template: path.resolve(__dirname, 'src/html', 'version.html'),
      filename: 'version.html',
      chunks: ['vendor', 'common', 'version'],
      inject: true,
      hash: true, //防止缓存
      minify: {
        removeAttributeQuotes: true, //压缩 去掉引号
        removeComments: true, //移除HTML中的注释
        collapseWhitespace: true //删除空白符与换行符
      }
    }),
    new HtmlWebpackPlugin({
      title: 'scale',
      template: path.resolve(__dirname, 'src/html', 'scale.html'),
      filename: 'scale.html',
      chunks: ['vendor', 'common', 'scale'],
      inject: true,
      hash: true, //防止缓存
      minify: {
        removeAttributeQuotes: true, //压缩 去掉引号
        removeComments: true, //移除HTML中的注释
        collapseWhitespace: true //删除空白符与换行符
      }
    }),
    new HtmlWebpackPlugin({
      title: 'emergency',
      template: path.resolve(__dirname, 'src/html', 'emergency.html'),
      filename: 'emergency.html',
      chunks: ['emergency', 'vendor', 'common'],
      inject: true,
      hash: true, //防止缓存
      minify: {
        removeAttributeQuotes: true, //压缩 去掉引号
        removeComments: true, //移除HTML中的注释
        collapseWhitespace: true //删除空白符与换行符
      }
    }),
    new HtmlWebpackPlugin({
      title: 'cdss',
      template: path.resolve(__dirname, 'src/html', 'cdss.html'),
      filename: 'cdss.html',
      chunks: ['cdss', 'vendor', 'common'],
      inject: true,
      hash: true, //防止缓存
      minify: {
        removeAttributeQuotes: true, //压缩 去掉引号
        removeComments: true, //移除HTML中的注释
        collapseWhitespace: true //删除空白符与换行符
      }
    }),
    new HtmlWebpackPlugin({
      title: 'cdssHorizontal',
      template: path.resolve(__dirname, 'src/html', 'cdssHorizontal.html'),
      filename: 'cdssHorizontal.html',
      chunks: ['cdssHorizontal', 'vendor', 'common'],
      inject: true,
      hash: true, //防止缓存
      minify: {
        removeAttributeQuotes: true, //压缩 去掉引号
        removeComments: true, //移除HTML中的注释
        collapseWhitespace: true //删除空白符与换行符
      }
    }),
    new HtmlWebpackPlugin({
      title: 'view',
      template: path.resolve(__dirname, 'src/html', 'view.html'),
      filename: 'view.html',
      chunks: ['view', 'vendor', 'common'],
      inject: true,
      hash: true, //防止缓存
      minify: {
        removeAttributeQuotes: true, //压缩 去掉引号
        removeComments: true, //移除HTML中的注释
        collapseWhitespace: true //删除空白符与换行符
      }
    }),
    new MiniCssExtractPlugin({
      filename: 'css/[name].css',
      chunkFilename: '[id].css'
    }),
    new webpack.HotModuleReplacementPlugin(),
    new CleanWebpackPlugin()
  ],
  optimization: { //webpack4.x的最新优化配置项，用于提取公共代码
    minimizer: [
      new UglifyJsPlugin({
        uglifyOptions: {
          ie8: true,
          compress: {
            properties: false,
            warnings: false
          },
          mangle: {
            screw_ie8: false,
            except: ['e']
          },
          output: {
            beautify: true
          },
          sourceMap: false
        }
      })
    ],
    splitChunks: {
      cacheGroups: {
        commons: {
          chunks: "initial",
          name: "common",
          minChunks: 2,
          maxInitialRequests: 5, // The default limit is too small to showcase the effect
          minSize: 0, // This is example is too small to create commons chunks
          reuseExistingChunk: true // 可设置是否重用该chunk
        }
      }
    }
  },

  module: {
    rules: [
      {
        test: /.js$/,
        enforce: 'post',
        loader: 'es3ify-loader'
      },
      {
        test: /\.m?js$/,
        exclude: /(node_modules|bower_components)/,
        use: {
          loader: 'babel-loader',
          options: {
            presets: ['@babel/preset-env']
          }
        }
      },
      {
        test: /\.css$/,
        use: [{
          loader: MiniCssExtractPlugin.loader
        },
          'css-loader'
        ]
      },
      {
        test: /\.less$/,
        use: [
          MiniCssExtractPlugin.loader,
          { loader: "css-loader" },
          { loader: "less-loader" }
        ]
      },
      {
        test: /\.(png|jpg|jpeg|gif|svg)$/,
        use: {
          loader: 'file-loader',
          options: {
            outputPath: 'images/', // 图片输出的路径和存储路径保持一致
            limit: 12000,
            name: '[name].[ext]'
          }
        }
      }
    ]
  },
  // devtool: 'cheap-module-eval-source-map', //开发环境cheap-module-eval-source-map   //生产环境cheap-module-source-map
  mode: 'development',
  devServer: {
    contentBase: "./dist", //静态文件根目录
    proxy: {
      '/sys': proxyHost,
      '/lantone': "http://114.55.109.16:81",
      '/kl': proxyHost,
    },
    hot: true,
    // openPage:'index.html?age=28&tipsName=血常规&tipsType=12&diseaseId=280&lisJson=&diagJson=急性胰腺炎&diseaseName=糖尿病&pastJson=无心脏病&otherJson=无高血压&pacsJson=腹部B超:无异常,%20报告日期:2019-05-07&sex=男&symptomJson=恶心呕吐腰痛&vitalJson=血压左上肢13/12mmHg&hospitalCode=A001',
    openPage:'homeStatic.html?mrId=200821362618001909&hospitalId=1&planCode=plan_default',
    disableHostCheck: true
  },
  stats: { children: false },

 
}