// var webpack = require("webpack");
var TerserPlugin = require("terser-webpack-plugin");
var devProxy = {
  "/api/": {
    target: process.env.VUE_APP_DEV_PROXY,
    changeOrigin: true
  }
};

// 配置手册： https://cli.vuejs.org/zh/config/#vue-config-js
var config = {
  // publicPath: './',
  devServer: {
    port: 8057,
    proxy: devProxy
  },
  transpileDependencies: ["vue-echarts", "resize-detector"],
  chainWebpack: config => {
    // webpack-chain配置手册：github.com/neutrinojs/webpack-chain#getting-started
    // 限制base64图片的大小在10kb以下
    config.module
      .rule("images")
      .use("url-loader")
      .loader("url-loader")
      .tap(options => Object.assign(options, { limit: 10240 }));
  }
};

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

module.exports = config;
