const { defineConfig } = require('@vue/cli-service')
const NodePolyfillPlugin = require('node-polyfill-webpack-plugin')
const path = require('path')
function resolve(dir) {
  return path.join(__dirname, dir)
}
module.exports = defineConfig({
  transpileDependencies: true,
  publicPath: "/",
  lintOnSave:false,
  transpileDependencies: true,
  productionSourceMap: false,
  devServer: {
    port: 1090,
    // proxy: {
    //   '/infoapi': {
    //     target: 'https://info.jiduzq.com/v1/',
    //     changeOrigin: true,
    //     pathRewrite: {
    //       '^/infoapi': '/'
    //     }
    //   },
    // }
  },
  configureWebpack: {
    // provide the app's title in webpack's name field, so that
    // it can be accessed in index.html to inject the correct title.
    name: 'name',
    resolve: {
      alias: {
        '@': resolve('src')
      },
      fallback: {
        //其他的如果不启用可以用 keyname :false，例如：crypto:false, 
        "crypto": require.resolve("crypto-browserify"),
        "stream": require.resolve("stream-browserify")
      },
    },
    optimization: {
      splitChunks: {
        chunks: 'all',
        minSize: 20000, // 拆分前模块的最小大小（以字节为单位）
        minChunks: 1, // 拆分前模块的最小块数
        maxAsyncRequests: 30, // 按需加载时并行请求的最大数量
        maxInitialRequests: 30, // 入口点处的最大并行请求数
        enforceSizeThreshold: 30000, // 如果拆分后的包超过此大小（以字节为单位），则尝试对其进行进一步拆分
        cacheGroups: {
          defaultVendors: {
            test: /[\\/]node_modules[\\/]/,
            priority: -10
          },
          default: {
            minChunks: 2,
            priority: -20,
            reuseExistingChunk: true
          }
        }
      }
    },
    output: {
      filename: `js/[name].js?[contenthash]`,
      chunkFilename: `js/[name].js?[contenthash]`,
    },
    plugins: [new NodePolyfillPlugin()]
  },
  css: {
    extract: {
      filename: `css/[name].css?[contenthash]`,
      chunkFilename: `css/[name].css?[contenthash]`,
    },
  },
})
