const path = require('path');
const CompressionWebpackPlugin = require('compression-webpack-plugin')
const cfg = require('./package.json');

function resolve(dir) {
  return path.join(__dirname, dir)
}

module.exports = {
  outputDir: "dist/" + cfg.version,
  productionSourceMap: false,
  chainWebpack: config => {
    config.resolve.alias
      .set('@', resolve('src/'))
      .set('#', resolve('src/components'))
      .set('%', resolve('src/res'))
  },
  devServer: {
    port: 9090,
    proxy: {
      '/api': {
        //测试环境
        target: 'http://47.99.245.36:8202',
        ws: true,
        changeOrigin: true,
        pathRewrite: {
          '^/api': '/'
        }
      },
    }
  },
  configureWebpack: config => {
    if (process.env.NODE_ENV === 'production') {
      config.plugins.push(new CompressionWebpackPlugin({
          algorithm: 'gzip',
          test: new RegExp('\\.(' + ['js', 'css'].join('|') + ')$'),
          threshold: 10240,
          minRatio: 0.8
        })
      )
    }
    config.externals = {
      'BMap':'BMap',
      'BMapLib':'BMapLib'
    }
  }
};
