const { defineConfig } = require("@vue/cli-service");
const WebpackObfuscator = require("webpack-obfuscator");
const path = require("path");
function resolve(dir) {
  return path.join(__dirname, "./", dir);
}

module.exports = defineConfig({
  transpileDependencies: true,
  publicPath: "/xdbs",
  productionSourceMap: false,
  devServer: {
    host: "0.0.0.0",
    port: 3000,
    open: true,
    proxy: {
      // https://cn.vitejs.dev/config/#server-proxy
      "/dev-api": {
        target: "http://localhost:8080",
        //target: 'http://62.234.3.186/prod-api/',
        changeOrigin: true,
        pathRewrite: {
          "^/dev-api": "/",
        },
      },
      "/xd/": {
        target: "http://localhost/xd",
        changeOrigin: true,
        pathRewrite: {
          "^/xd/": "/",
        },
      },
      "/cesium": {
        target: `http://62.234.3.186/cesium/`,
        changeOrigin: true,
        pathRewrite: {
          "^/cesium": "/",
        },
      },
      "/cdn": {
        target: `http://62.234.3.186/cdn/`,
        changeOrigin: true,
        pathRewrite: {
          "^/cdn": "/",
        },
      },
      "/statics/": {
        target: `http://localhost:9300/statics/`,
        changeOrigin: true,
        pathRewrite: {
          "^/statics/": "/",
        },
      },
    },
  },
  chainWebpack: (config) => {
    config.module.rule("svg").exclude.add(resolve("src/assets/icons")).end();
    config.module
      .rule("icons")
      .test(/\.svg$/)
      .include.add(resolve("src/assets/icons"))
      .end()
      .use("svg-sprite-loader")
      .loader("svg-sprite-loader")
      .options({
        symbolId: "myicon-[name]",
      });
  },
  configureWebpack: (config) => {
    config.externals = {
      vue: "Vue",
    };
    if (process.env.NODE_ENV === "production") {
      /*
      config.plugins.push(
        new WebpackObfuscator(
          {
            rotateStringArray: true, // 旋转字符串数组
            stringArray: true, // 使用字符串数组
            stringArrayEncoding: ["rc4"], // 字符串数组编码(rc4 是一个强加密算法)
            stringArrayThreshold: 0.75, // 混淆代码中的字符串百分比
            deadCodeInjection: true, // 注入死代码
            deadCodeInjectionThreshold: 0.4, // 死代码注入比例
            unicodeEscapeSequence: false, // 使用Unicode转义序列
            debugProtection: true, // 防止浏览器的开发者工具调试
            disableConsoleOutput: true, // 禁用 console.log、console.info 等输出
          },
          [] // 需要排除混淆的文件
        )
      );
      */
    }
  },
});