const path = require('path');

const ManifestPlugin = require('webpack-manifest-plugin');
const DynamicCdnWebpackPlugin = require('dynamic-cdn-webpack-plugin');
const { IgnorePlugin } = require('webpack');

module.exports = {
  entry: {
    app: './src/components/RenderRouter/RenderRouter.tsx',
  },
  resolve: {
    // Add `.ts` and `.tsx` as a resolvable extension.
    extensions: ['.mjs', '.ts', '.tsx', '.js', '*.scss'],
  },
  module: {
    rules: [
      // all files with a `.ts` or `.tsx` extension will be handled by `ts-loader`
      { test: /\.tsx?$/, loader: 'ts-loader' },
      {
        test: /\.(svg|png|jpg|gif)$/i,
        use: [
          {
            loader: 'url-loader',
            options: {
              limit: 8192,
            },
          },
        ],
      },
      {
        test: /\.scss$/,
        use: [
          {
            loader: 'style-loader',
          },
          {
            loader: 'css-loader',
          },
          {
            loader: 'sass-loader',
          },
        ],
      },
    ],
  },
  plugins: [
    new IgnorePlugin({
      resourceRegExp: /dist/,
    }),
  ],
  output: {
    path: path.resolve(__dirname, 'build'),
    filename: 'webpack-render-router.js',
    library: 'tmhRenderRouter',
  },

  plugins: [
    new ManifestPlugin({
      fileName: 'manifest.json',
    }),
    new DynamicCdnWebpackPlugin(),
  ],
};
