const path = require("path");
const webpack = require("webpack");
const CleanWebpackPlugin = require("clean-webpack-plugin");
const ContextReplacementPlugin = require("webpack/lib/ContextReplacementPlugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");

module.exports = {
  entry: {
    main: "src/portal.js"
  },
  output: {
    filename: "[name].js",
    path: path.resolve(__dirname, "dist")
  },
  module: {
    rules: [
      {
        test: /\.js?$/,
        exclude: [path.resolve(__dirname, "node_modules")],
        use: { loader: "babel-loader" }
      },
      {
        test: /\.html$/,
        use: [
          {
            loader: "html-loader",
            options: { minimize: true }
          }
        ]
      },
      {
        test: /\.css$/,
        use: ["vue-style-loader", "css-loader"]
      },
      {
        test: /\.scss$/,
        loaders: ["vue-style-loader", "css-loader", "sass-loader"]
      }
    ]
  },
  node: {
    fs: "empty"
  },
  resolve: {
    modules: [__dirname, "node_modules"]
  },
  plugins: [
    CopyWebpackPlugin([
      { from: path.resolve(__dirname, "src") },
      { from: path.resolve(__dirname, "libs") }
      // { from: path.resolve(__dirname, 'libs/system.js') },
      // { from: path.resolve(__dirname, 'libs/jquery.min.js') },
      // { from: path.resolve(__dirname, 'libs/base64.min.js') },
      // { from: path.resolve(__dirname, 'libs/Loadwebsign.js') },
      // { from: path.resolve(__dirname, 'libs/polyfill.js') },
    ]),
    new CleanWebpackPlugin(["portal"])
  ],
  devtool: "source-map",
  externals: [],
  mode: "development",
  devServer: {
    host: 'localhost',
    openPage: "login.html",
    contentBase: "./",
    historyApiFallback: true,
    watchOptions: { aggregateTimeout: 300, poll: 1000 },
    // headers: {
    // 	"Access-Control-Allow-Origin": "*",
    // 	"Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, PATCH, OPTIONS",
    // 	"Access-Control-Allow-Headers": "X-Requested-With, content-type, Authorization"
    // },
    // Proxy config for development purposes. In production, you would configure you webserver to do something similar.
    proxy: {


      "/accountability": {
        //通用功能子系統
        target: "http://localhost:8088",
        pathRewrite: { "^/accountability": "" }
      },
      "/publicfunction": {
        //通用功能子系統
        target: "http://localhost:9001",
        pathRewrite: { "^/publicfunction": "" }
      },
      "/grainCoManage": {
        target: "http://localhost:9002",
        pathRewrite: { "^/grainCoManage": "" }
      },
      "/ywbb": {
        target: "http://localhost:9003",
        pathRewrite: { "^/ywbb": "" }
      },
      "/grainReserves": {
        target: "http://localhost:9004",
        pathRewrite: { "^/grainReserves": "" }
      },
      "/grainreservesArea": {
        target: "http://localhost:8001",
        pathRewrite: { "^/grainreservesArea": "" }
      },
      "/grainReservesFirm": {
        target: "http://localhost:9007",
        pathRewrite: { "^/grainReservesFirm": "" }
      },
      "/emergency": {
        target: "http://localhost:9005",
        pathRewrite: { "^/emergency": "" }
      },
      "/financial": {
        target: "http://localhost:9001",
        pathRewrite: { "^/financial": "" }
      },
      "/quality": {
        target: "http://localhost:9008",
        pathRewrite: { "^/quality": "" }
      },
      //预警系统
      "/earlyWarning": {
        target: "http://localhost:9017",
        pathRewrite: { "^/earlyWarning": "" }
      },
      // "/myuser": {
      // 	target: "http://218.241.206.66:8097/myuser",
      // 	pathRewrite: {"^/myuser" : ""},
      // },
      "/myuser": {
        target: "http://192.168.80.230:8097/myuser",
        pathRewrite: { "^/myuser": "" }
      },
      "/monitor": {
        target: "http://localhost:9006",
        pathRewrite: { "^/monitor": "" }
      },
      "/main": {
        target: "http://10.223.3.39:9090",
        secure: false, // 如果是https接口，需要配置这个参数
        changeOrigin: true, // 如果接口跨域，需要进行这个参数配置
        pathRewrite: { "^/main": "" }
      },
      "/tjapi": {
        target: "http://101.36.160.140:8097",
        secure: false, // 如果是https接口，需要配置这个参数
        changeOrigin: true, // 如果接口跨域，需要进行这个参数配置
        pathRewrite: { "^/tjapi": "" }
      },
      "/nmapi": {
        target: "http://101.36.160.140:8097",
        secure: false, // 如果是https接口，需要配置这个参数
        changeOrigin: true, // 如果接口跨域，需要进行这个参数配置
        pathRewrite: { "^/nmapi": "" }
      },
      "/fileApi": {
        target: "http://172.16.0.73:11010",
        secure: false, // 如果是https接口，需要配置这个参数
        changeOrigin: true, // 如果接口跨域，需要进行这个参数配置
        pathRewrite: { "^/fileApi": "" }
      },
      "/huyong": {
        target: "http://192.168.50.198:13100/cbl",
        secure: false, // 如果是https接口，需要配置这个参数
        changeOrigin: true, // 如果接口跨域，需要进行这个参数配置
        pathRewrite: { "^/huyong": "" }
      },
      "/unitApi": {
        target: "http://192.168.123.15:8098",
        secure: false, // 如果是https接口，需要配置这个参数
        changeOrigin: true, // 如果接口跨域，需要进行这个参数配置
        pathRewrite: { "^/unitApi": "" }
      },
      "/todoApi": {
        target: "http://101.36.160.140:8097",
        secure: false, // 如果是https接口，需要配置这个参数
        changeOrigin: true, // 如果接口跨域，需要进行这个参数配置
        pathRewrite: { "^/todoApi": "" }
      },
      "/circulate": {
        target: "http://localhost:9010",
        pathRewrite: { "^/circulate": "" }
      },
      "/transaction": {
        target: "http://localhost:9011",
        pathRewrite: { "^/transaction": "" }
      },
      "/decision": {
        target: "http://localhost:9012",
        pathRewrite: { "^/decision": "" }
      },
      "/inspection": {
        target: "http://localhost:9009",
        pathRewrite: { "^/inspection": "" }
      },
      "/headResponsibility": {
        target: "http://localhost:9010",
        pathRewrite: { "^/headResponsibility": "" }
      },
      "/industry": {
        target: "http://localhost:9100",
        pathRewrite: { "^/industry": "" }
      },
      "/safetyProduction": {
        target: "http://localhost:9999",
        pathRewrite: { "^/safetyProduction": "" }
      },
      "/systemSetting": {
        target: "http://localhost:2019",
        pathRewrite: { "^/systemSetting": "" }
      },
      "/webDecision": {
        target: "http://localhost:9013",
        pathRewrite: { "^/webDecision": "" }
      },
      "/projectmanage": {
        target: "http://localhost:9099",
        pathRewrite: { "^/projectmanage": "" }
      },
      "/log": {
        target: "http://localhost:9014",
        pathRewrite: { "^/log": "" }
      },
      "/safeProduction": {
        target: "http://localhost:9015",
        pathRewrite: { "^/safeProduction": "" }
      },
      "/hlht": {
        target: "http://101.36.160.140:8097/hlht",
        secure: false, // 如果是https接口，需要配置这个参数
        changeOrigin: true, // 如果接口跨域，需要进行这个参数配置
        pathRewrite: { "^/hlht": "" }
      },
      "/operationservices": {
        //yunwei
        target: "http://localhost:9016",
        pathRewrite: { "^/operationservices": "" }
      },
      "/kjdepot": {
          target: "http://172.16.0.73:8889",
          pathRewrite: { "^/kjdepot": "" }
      },
      "/depot": {
          target: "http://101.36.160.140:8097/medicament",
          pathRewrite: { "^/depot": "" }
      },
      "/irpt-server": {
          target: "http://172.16.0.72:12032",
          pathRewrite: { "^/irpt-server": "" }
      },
      "/file": {
          target: "http://172.16.0.73:11010",
          pathRewrite: { "^/file": "" }
      },
      "/base-server": {
          target: "http://172.16.0.73:14100",
          pathRewrite: { "^/base-server": "" }
      },
      "/safety-service": {
          target: "http://172.16.0.72:13880",
          pathRewrite: { "^/safety-service": "" }
      },
      "/cjjd": {
          target: "http://172.16.0.72:8068",
          pathRewrite: { "^/cjjd": "" }
      },
    }
  }
};
