const path = require('path');
const TerserPlugin = require('terser-webpack-plugin');

module.exports = {
  mode: 'production',
  target: "web",
  entry: path.resolve(__dirname, 'module.ts'),
  output: {
      path: path.resolve(__dirname, '../../dist'),
      filename: 'FrontendPlugin.js',
      libraryTarget: 'commonjs',
  },
  resolve: {
    // Add `.ts` and `.tsx` as a resolvable extension.
    extensions: [".ts", ".tsx", ".js"]
  },
  module: {
    rules: [
      { test: /\.ts?$/, loader: "ts-loader" }
    ]
  },
  optimization: {
    minimizer: [
      new TerserPlugin({
        exclude: [
          /\.\/(.*)\/.ts/,
          /\.\/(.*).ts/,
        ],
      }),
    ],
  },
  externals: {
    '@angular/core': '@angular/core',
    '@angular/common': '@angular/common',
    '@angular/router': '@angular/router',
    '@angular/animations': '@angular/animations',
    '@angular/forms': '@angular/forms',
    '@clr/angular': '@clr/angular'
  }
}
