const path = require('path');

module.exports = {
  mode: 'production', // 或 'development'
  entry: './src/server.ts', // 你的主入口点
  target: 'node', // 针对 Node.js，不会打包内置模块如 fs、path 等
  module: {
    rules: [
      {
        test: /\.tsx?$/, 
        use: 'ts-loader', 
        exclude: /node_modules/,
      },
    ],
  },
  resolve: {
    extensions: ['.tsx', '.ts', '.js'], // 自动解析确定的扩展
  },
  output: {
    filename: 'app.js', // 输出的打包文件
    path: path.resolve(__dirname, 'dist'), 
  },
  externals: {
    // 排除有问题的二进制模块和可选依赖
    'kerberos': 'commonjs kerberos',
    'snappy': 'commonjs snappy',
    'bson-ext': 'commonjs bson-ext',
    '@mongodb-js/zstd': 'commonjs @mongodb-js/zstd',
    'mongodb-client-encryption': 'commonjs mongodb-client-encryption',
    '@napi-rs/snappy-darwin-arm64': 'commonjs @napi-rs/snappy-darwin-arm64',
    '@napi-rs/snappy-darwin-x64': 'commonjs @napi-rs/snappy-darwin-x64',
    '@napi-rs/snappy-linux-x64-gnu': 'commonjs @napi-rs/snappy-linux-x64-gnu',
    '@napi-rs/snappy-linux-x64-musl': 'commonjs @napi-rs/snappy-linux-x64-musl',
    '@napi-rs/snappy-linux-arm64-gnu': 'commonjs @napi-rs/snappy-linux-arm64-gnu',
    '@napi-rs/snappy-linux-arm64-musl': 'commonjs @napi-rs/snappy-linux-arm64-musl',
    '@napi-rs/snappy-linux-arm-gnueabihf': 'commonjs @napi-rs/snappy-linux-arm-gnueabihf',
    '@napi-rs/snappy-linux-arm-musleabihf': 'commonjs @napi-rs/snappy-linux-arm-musleabihf',
    '@napi-rs/snappy-linux-riscv64-gnu': 'commonjs @napi-rs/snappy-linux-riscv64-gnu',
    '@napi-rs/snappy-linux-riscv64-musl': 'commonjs @napi-rs/snappy-linux-riscv64-musl',
    '@napi-rs/snappy-linux-ppc64-gnu': 'commonjs @napi-rs/snappy-linux-ppc64-gnu',
    '@napi-rs/snappy-linux-s390x-gnu': 'commonjs @napi-rs/snappy-linux-s390x-gnu',
    '@napi-rs/snappy-openharmony-arm64': 'commonjs @napi-rs/snappy-openharmony-arm64',
    '@napi-rs/snappy-openharmony-x64': 'commonjs @napi-rs/snappy-openharmony-x64',
    '@napi-rs/snappy-openharmony-arm': 'commonjs @napi-rs/snappy-openharmony-arm',
    '@napi-rs/snappy-wasm32-wasi': 'commonjs @napi-rs/snappy-wasm32-wasi',
    '@napi-rs/snappy-freebsd-x64': 'commonjs @napi-rs/snappy-freebsd-x64',
    '@napi-rs/snappy-freebsd-arm64': 'commonjs @napi-rs/snappy-freebsd-arm64'
  },
  // 添加忽略警告的配置
  ignoreWarnings: [
    /Critical dependency: the request of a dependency is an expression/,
    /Module not found: Error: Can't resolve 'bson-ext'/,
    /Package path .* is not exported from package/
  ],
};