const path = require('path');
const tsConfigPath = path.join(__dirname, 'tsconfig.json');

module.exports = {
  context: path.join(__dirname),
  mode: 'production',
  target: 'node',
  entry: {
    extension: './src/extension.ts',
  },
  output: {
    filename: '[name].js',
    path: path.join(__dirname, 'dist'),
    libraryTarget: 'commonjs',
  },
  node: {
    __dirname: false,
  },
  externals: {
    vscode: 'commonjs vscode',
    bufferutil: 'bufferutil',
    'utf-8-validate': 'utf-8-validate',
  },
  devtool: false,
  resolve: {
    mainFields: ['module', 'main'],
    extensions: ['.ts', '.js'],
  },
  module: {
    // 删除本地debug cookie
    rules: [
      {
        test: /util\.ts$/,
        use: [
          {
            loader: 'string-replace-loader',
            options: {
              search: 'debug=start;(.*)debug=end',
              replace: '',
              flags: 'g',
            },
          },
        ],
      },
      {
        test: /\.ts$/,
        exclude: /node_modules/,
        use: [
          {
            loader: 'ts-loader',
            options: {
              compilerOptions: {
                sourceMap: false,
              },
              transpileOnly: true,
              configFile: tsConfigPath,
            },
          },
        ],
      },
    ],
  },
};
