const CompressionWebpackPlugin = require('compression-webpack-plugin'); // 开启压缩
// const isProduction = process.env.NODE_ENV === 'production';

module.exports = {
  publicPath: './',
  productionSourceMap: false,
  devServer: {
    port: 8081,
    proxy: {
      '/test/face': {
        target: 'https://facegame.platomix.net',
        pathRewrite: {
          '^/test/face': '/'
        }
      }
    },
  },
  pages: {
    mobile: {
      entry: 'src/mobile.js',
      template: 'public/mobile.html',
      filename: 'mobile.html'
    },
    index: {
      entry: 'src/main.js',
      template: 'public/index.html',
      filename: 'index.html'
    },
  },
  chainWebpack: config => {
    config.plugins.delete('prefetch')
  },
  css: {
    loaderOptions: {
      css: {},
      postcss: {
        plugins: [
          require('postcss-plugin-px2rem')({
            rootValue: 75,
            exclude: /(node_module)/,
          }),
        ]
      },
      sass: {
        prependData: `@import "./src/styles/mixin.scss";`
      }
    }
  },
  configureWebpack: config => {
    const plugins = [];
    // 服务器也要相应开启gzip
    plugins.push(
      new CompressionWebpackPlugin({
        algorithm: 'gzip',
        test: /\.(js|css)$/, // 匹配文件名
        threshold: 10000, // 对超过10k的数据压缩
        deleteOriginalAssets: false, // 不删除源文件
        minRatio: 0.8 // 压缩比
      })
    )

    return {
      plugins
    }
  }
}
