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: 8056,
    proxy: devProxy
  },
  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"
      }
    ]);
    // 限制base64图片的大小在20kb以下
    config.module
      .rule("images")
      .use("url-loader")
      .loader("url-loader")
      .tap(options => Object.assign(options, { limit: 20480 }));
  }
};

// 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;
