/* eslint-disable */
const path = require("path");
const devProxy = require("./config/proxy"); // 代理

// 自动化导入scss --颜色
function addStyleResource(rule) {
  rule
    .use(["style-loader", "css-loader", "sass-loader"])
    .loader("style-resources-loader")
    .options({
      patterns: [path.resolve(__dirname, "./src/assets/styles/colors.scss")]
    });
}

module.exports = {
  productionSourceMap: process.env.NODE_ENV !== "production",
  publicPath: process.env.NODE_ENV === "production" ? "/welfare" : "/",
  devServer: {
    // port: 8017,
    overlay: {
      warnings: true,
      errors: true
    },
    proxy: devProxy.proxyList // string | Object
  },
  chainWebpack: config => {
    const types = ["vue-modules", "vue", "normal-modules", "normal"];
    types.forEach(type =>
      addStyleResource(config.module.rule("scss").oneOf(type))
    );
    // ============压缩图片 start============
    // config.module
    //   .rule('images')
    //   .use('image-webpack-loader')
    //   .loader('image-webpack-loader')
    //   .options({ bypassOnDebug: true })
    //   .end();
    // ============压缩图片 end============
  },
  configureWebpack: config => {
    config.externals = {
      vue: 'Vue',
      'vue-router': 'VueRouter',
      vuex: 'Vuex',
      axios: 'axios',
      // 'element-ui': 'ELEMENT',
    };
    if (process.env.NODE_ENV === 'production') {
      config.optimization.minimizer[0].options.terserOptions.compress.warnings = false;
      config.optimization.minimizer[0].options.terserOptions.compress.drop_console = true;
      config.optimization.minimizer[0].options.terserOptions.compress.drop_debugger = true;
      config.optimization.minimizer[0].options.terserOptions.compress.pure_funcs = [
        'console.log'
      ];
    }
  }
};