const path = require('path')

function resolve(dir) {
  return path.join(__dirname, dir)
}
module.exports = {
  publicPath: './',
  outputDir: 'dist',
  assetsDir: 'static',
  productionSourceMap: false,
  filenameHashing: false,
  lintOnSave: false,
  css: {
    requireModuleExtension: true
  },
  devServer: {
    port: 8888, // 端口
    open: true, // 启动后打开浏览器
  },
  chainWebpack: config => {
    //最小化代码
    config.optimization.minimize(true)
    //分割代码
    config.optimization.splitChunks({
      chunks: 'all'
    })
    // //压缩图片
    // config.module
    //   .rule('images')
    //   .use('image-webpack-loader')
    //   .loader('image-webpack-loader')
    //   .options({
    //     bypassOnDebug: true
    //   })
    //   .end()
    //set svg-sprite-loader
    config.module.rule('svg').exclude.add(resolve('src/icon')).end()
    config.module
      .rule('icons')
      .test(/\.svg$/)
      .include.add(resolve('src/icon'))
      .end()
      .use('svg-sprite-loader')
      .loader('svg-sprite-loader')
      .options({
        symbolId: 'icon-[name]'
      })
      .end()
  },
  configureWebpack: config => {
    // 打包文件大小配置
    config.performance = {
      maxEntrypointSize: 10000000,
      maxAssetSize: 30000000
    }
  }
}
