const webpack = require("webpack");
const path = require("path");
const FileManagerPlugin = require("filemanager-webpack-plugin");

function resolve(dir) {
  return path.join(__dirname, dir);
}
module.exports = {
  publicPath: "./",
  assetsDir: "static",
  devServer: {
    disableHostCheck: true, //内网穿透
    host: "0.0.0.0",
    port: 3007,
    https: false, // https:{type:Boolean}
    open: true,
    proxy: {
      "/api": {
        // target: 'https://health.sh-sict.com/wjy-api',
        // target: 'https://inno.sh-sict.com/wjy-api',
        target: 'https://zcas.wzswsj.gov.cn/screening-api/',
        // target: "https://ds.cixincloud.com/screening-api/",
        // target: 'https://inno.sh-sict.com/screening-wjy/',
        // target: 'https://220.191.206.119/screening-api/',
        changeOrigin: true,
        ws: false, //关闭ws代理
        pathRewrite: {
          "^/api": ""
        }
      }
    }
  },
  configureWebpack: {
    devtool: "source-map",
    plugins: [
      new FileManagerPlugin({
        events: {
          onEnd: {
            delete: ["./dist/*.zip"],
            archive: [{ source: "./dist", destination: `./dist.zip` }]
          }
        }
      })
    ]
  },
  chainWebpack: (config) => {
    config.resolve.alias
      .set("@", resolve("src")) // key,value自行定义，比如.set('@@', resolve('src/components'))
      .set("_c", resolve("src/components"));
    config.when(process.env.NODE_ENV === "production", (config) => {
      config
        .plugin("fileManager")
        .use(FileManagerPlugin, [
          {
            onEnd: {
              // delete: [`./dist`, `./dist`],
              archive: [
                {
                  source: `./dist`,
                  destination: `./dist/dist.zip`
                }
              ]
            }
          }
        ])
        .end();
    });
  },
  productionSourceMap: false,
  lintOnSave: false
};
