var webpack = require("webpack");
var TerserPlugin = require("terser-webpack-plugin");
var CompressionPlugin = require("compression-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
var config = {
  // publicPath: './',
  devServer: {
    port: 8076
  },
  chainWebpack: config => {
    // webpack-chain配置手册：github.com/neutrinojs/webpack-chain#getting-started
    // config.plugin("provide").use(webpack.ProvidePlugin, [
    //   {
    //     "window.Quill": "quill/dist/quill.js",
    //     Quill: "quill/dist/quill.js"
    //   }
    // ]);
  }
};

// compress配置手册：https://github.com/mishoo/UglifyJS2/tree/harmony#compress-options
if (process.env.NODE_ENV === "production") {
  config.configureWebpack = {
    plugins: [
      // gzip
      new CompressionPlugin({
        filename: "[path].gz[query]",
        algorithm: "gzip",
        test: new RegExp("\\.(js|css)$"),
        threshold: 10240,
        minRatio: 0.8
      })
    ],
    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;
