const TerserPlugin = require('terser-webpack-plugin')
const CompressionWebpackPlugin = require('compression-webpack-plugin')

module.exports = {
    // ...other vue-cli plugin options...

    css: {
      loaderOptions: {
        less: {
          javascriptEnabled: true, // 加载LESS 需要把JS设置一下
        }
      }
    },
    devServer: {
      proxy: { // 设置代理
        '/api': {
          target: 'http://172.16.100.93:8901',
          changeOrigin: true,
          pathRewrite: {
            '^/api': ''
          }
        },
      }
    },
    configureWebpack: config => {
      if (process.env.NODE_ENV === 'production') {
        config.optimization = {
          minimize: true,
          minimizer: [
            new TerserPlugin({
              exclude: /node_modules/,
              terserOptions: {
                compress: {
                  drop_console: true,
                  drop_debugger: false,
                  pure_funcs: ['console.log'], // 移除console
                }
              }
            })
          ]
        }
        // config.plugins = [
        //   new CompressionWebpackPlugin({
        //     filename: '[path][name].gz[query]',
        //     algorithm: 'gzip',
        //     test: /\.(js|css|json|ttf)(\?.*)?$/i,
        //     threshold: 0,
        //     minRatio: 0.8,
        //   })
        // ]
      }
    }
    // pwa: {
    //   name: 'My App',
    //   themeColor: '#4DBA87',
    //   msTileColor: '#000000',
    //   appleMobileWebAppCapable: 'yes',
    //   appleMobileWebAppStatusBarStyle: 'black',
    //   manifestOptions:{
    //     display: 'standalone',
    //     theme_color: '#333333'
    //   },
    //   // configure the workbox plugin
    //   workboxPluginMode: 'InjectManifest',
    //   workboxOptions: {
    //     // swSrc is required in InjectManifest mode.
    //     // swSrc: 'dev/sw.js',
    //     // ...other Workbox options...
    //   }
    // }
  }