const path = require('path');
const frameSrc = path.resolve(__dirname, '../admin-frame');
const packageName = require('./package.json').name;
// 导入compression-webpack-plugin
const CompressionWebpackPlugin = require('compression-webpack-plugin');
// 定义压缩文件类型
const productionGzipExtensions = ['js', 'css'];
module.exports = {
  publicPath: `/${packageName}/`,
  outputDir: path.join(frameSrc, `../../admin-web/${packageName}/`),
  devServer: {
    port: 3001,
    headers: {
      'Access-Control-Allow-Origin': '*'
    },
    proxy: {
      '/api/': {
        // target: 'http://192.168.0.45:18090'
        target: 'http://127.0.0.1:18090'
      }
    }
  },
  configureWebpack: {
    output: {
      library: `${packageName}-[name]`,
      libraryTarget: 'umd',
      jsonpFunction: `webpackJsonp_${packageName}`
    },
    resolve: {
      alias: {
        '@components': path.join(frameSrc, '/src/components'),
        '@style': path.join(frameSrc, '/style'),
        '@lib': path.join(frameSrc, '/lib')
      }
    },
    plugins: [
      new CompressionWebpackPlugin({
        filename: '[path].gz[query]',
        algorithm: 'gzip',
        test: new RegExp('\\.(' + productionGzipExtensions.join('|') + ')$'),
        threshold: 10240,
        minRatio: 0.8
      })
    ]
  }
};