const path = require("path");
module.exports = {
  // 基本路径
  publicPath: process.env.NODE_ENV === "production" ? "" : "/",
  // 输出文件目录
  outputDir: process.env.NODE_ENV === "production" ? "dist" : "devdist",
  // eslint-loader 是否在保存的时候检查
  lintOnSave: false,

  /** vue3.0内置了webpack所有东西，
   * webpack配置,see https://github.com/vuejs/vue-cli/blob/dev/docs/webpack.md
   **/
  chainWebpack: (config) => {
    const svgRule = config.module.rule("svg");
    svgRule.uses.clear();
    svgRule
      .use("svg-sprite-loader")
      .loader("svg-sprite-loader")
      .options({
        symbolId: "icon-[name]",
        include: ["./src/icons"],
      });

    config.module
      .rule("pug")
      .test(/\.pug$/)
      .use("pug-html-loader")
      .loader("pug-html-loader")
      .end();
  },
  configureWebpack: (config) => {
    config.resolve = {
      // 配置解析别名
      extensions: [".js", ".json", ".vue"], // 自动添加文件名后缀
      alias: {
        vue: "vue/dist/vue.js",
        "@": path.resolve(__dirname, "./src"),
        "@c": path.resolve(__dirname, "./src/components"),
      },
    };
  },
  // 生产环境是否生成 sourceMap 文件
  productionSourceMap: false,
  // css相关配置
  css: {
    // 是否使用css分离插件 ExtractTextPlugin
    extract: true,
    // 开启 CSS source maps?
    sourceMap: false,
    // css预设器配置项
    loaderOptions: {
      sass: {
        prependData: `@import "./src/styles/main.css";`,
      },
    },
    // 启用 CSS modules for all css / pre-processor files.
    requireModuleExtension: true, // 是否开启支持‘foo.module.css’样式
  },
  // use thread-loader for babel & TS in production build
  // enabled by default if the machine has more than 1 cores
  parallel: require("os").cpus().length > 1,
  /**
   *  PWA 插件相关配置,see https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-pwa
   */
  pwa: {},

  // webpack-dev-server 相关配置
  devServer: {
    open: false, // 编译完成是否打开网页
    host: "0.0.0.0", // 指定使用地址，默认localhost,0.0.0.0代表可以被外界访问
    port: 8050, // 访问端口
    https: false, // 编译失败时刷新页面
    hot: true, // 开启热加载
    hotOnly: false,
    proxy: {
      // 配置跨域
      "/devApi": {
        //要访问的跨域的api的域名
        target: "http://localhost:3000",
        ws: true,
        changOrigin: true,
        pathRewrite: {
          "^/devApi": "",
        },
      },
    },
    overlay: {
      // 全屏模式下是否显示脚本错误
      warnings: true,
      errors: true,
    },
    before: (app) => {},
  },
  /**
   * 第三方插件配置
   */
  pluginOptions: {
    electronBuilder: {
      builderOptions: {
        asar: false,
        extraResources: [
          {
            from: "./print/",
            to: "../print",
          },
          {
            from: "./print4.0/",
            to: "../print4.0",
          },
          {
            from: "./print600/",
            to: "../print600",
          },
          {
            from: "./logs/",
            to: "../logs",
          },
          {
            from: "./config/",
            to: "../config",
          },
          {
            from: "scripts", // 本地脚本目录
            to: "scripts", // 输出到 resources/scripts
            filter: ["**/*"], // 包含所有文件
          },
        ],

        win: {
          requestedExecutionLevel: "requireAdministrator",
          target: [
            {
              target: "nsis",
              arch: ["x64", "ia32"], // 支持64位和32位系统
            },
          ],
        },
        nsis: {
          oneClick: false, // 禁用一键安装
          allowToChangeInstallationDirectory: true, // 允许用户更改安装目录
          perMachine: true, // 为所有用户安装
        },
      },
    },
  },
};
