var TerserPlugin = require("terser-webpack-plugin");
var devProxy = {};
try {
  devProxy = require("./dev-proxy");
} catch (error) {}

var proxy = process.env.NODE_ENV === "production" ? {} : devProxy;

// 配置手册： https://cli.vuejs.org/zh/config/#vue-config-js
// electron-bulder配置：https://www.electron.build/configuration/contents#extrafiles
var config = {
  // publicPath: './',
  devServer: {
    port: 8066
  },
  pluginOptions: {
    electronBuilder: {
      builderOptions: {
        extraFiles: ["extra/**"]
      }
    }
  }
};

// compress配置手册：https://github.com/mishoo/UglifyJS2/tree/harmony#compress-options
if (process.env.NODE_ENV === "production") {
  config.configureWebpack = {
    plugins: [],
    optimization: {
      minimizer: [
        new TerserPlugin({
          terserOptions: { compress: { drop_console: true } }
        })
      ]
    }
  };
}

if (proxy && Object.keys(proxy).length) {
  config.devServer.proxy = proxy;
}

// 解决iview自定义主题导入less报错
config.css = {
  loaderOptions: {
    less: {
      javascriptEnabled: true
    }
  }
};

module.exports = config;
