
const path = require('path');

const UglifyJsWebpackPlugin = require( 'uglifyjs-webpack-plugin' );

module.exports = {
  type: 'react-app',
  npm: {
    esModules: true,
    umd: {
      global: 'ReactNwbSite',
      externals: {
        react: 'React',
      },
    },
  },
  webpack: {
    extra: {
      entry: './src/index',
      resolve: {
        extensions: ['.ts', '.tsx', '.js', '.jsx'],
      },
      output: {
        // The name under which the uploader will be exported.
        library: 'ReactUploader',
    
        path: path.resolve( __dirname, 'build' ),
        filename: 'index.js',
        libraryTarget: 'umd',
        libraryExport: 'default'
      },
      module: {
        rules: [
          { test: /\.tsx?$/, loader: ["awesome-typescript-loader"] },
          {
            test: /\.(sa|sc)ss$/,
            use: [
              "style-loader", // creates style nodes from JS strings
              "css-loader",
              "sass-loader", // compiles Sass to CSS, using Node Sass by default,
            ],
          },
        ]
      },
      optimization: {
        minimizer: [
          new UglifyJsWebpackPlugin( {
            sourceMap: true,
            uglifyOptions: {
              output: {
                // Preserve CKEditor 5 license comments.
                comments: /^!/
              }
            }
          } )
        ]
      }
    }
  },
  devServer: {
    // compress: true,
    // hot: true,
    // host: '0.0.0.0',
    port: 8000,
    disableHostCheck: true,
    proxy: {
      '/api': {
        target: 'http://localhost:8080/sip-api',
        ws: true,
        changeOrigin: true,
        pathRewrite: {
          '^/api': ''
        }
      }
    }
  }
}
