text: const path = require('path');
  const webpack = require('webpack');
  const ExtractTextPlugin = require('extract-text-webpack-plugin');
  //const CheckerPlugin = require('awesome-typescript-loader').CheckerPlugin;
  const { CheckerPlugin } = require('awesome-typescript-loader');
  const merge = require('webpack-merge');
  const CircularDependencyPlugin = require('circular-dependency-plugin');
  
  module.exports = (env) => {
      const isDevBuild = !(env && env.prod);
  
      // Configuration in common to both client-side and server-side bundles
      const sharedConfig = () => ({
          stats: { modules: true },
          resolve: {
              extensions: ['.js', '.jsx', '.ts', '.tsx'],
              alias: {
                  "@app": path.resolve(__dirname, "./ClientApp/"),
                  "@middlewares": path.resolve(__dirname, "./ClientApp/middlewares/"),
                  //"@components": path.resolve(__dirname, "./ClientApp/components/"),
                  "ClientApp": path.resolve(__dirname, "./ClientApp/"),
              }
          },
          output: {
              libraryTarget: "umd",
              filename: '[name].js',
              publicPath: 'dist/' // Webpack dev middleware, if enabled, handles requests for this URL prefix
          },
          module: {
              rules: [
                  { test: /\.(tsx|ts)?$/, include: /ClientApp/, use: 'awesome-typescript-loader' },
                  //{ test: /\.ts?$/, include: /ClientApp/, use: 'awesome-typescript-loader?silent=true' },
                  { test: /\.(png|jpg|jpeg|gif|svg)$/, use: 'url-loader?limit=25000' }
              ]
          },
          plugins: [
              new CheckerPlugin(),
              new CircularDependencyPlugin({
                  // exclude detection of files based on a RegExp
                  exclude: /a\.js|node_modules/,
                  // add errors to webpack instead of warnings
                  failOnError: true,
                  // set the current working directory for displaying module paths
                  cwd: process.cwd(),
              })],
          watchOptions: {
              poll: true
          }
      });
  
      // Configuration for client-side bundle suitable for running in browsers
      const clientBundleOutputDir = './wwwroot/dist';
      const clientBundleConfig = merge(sharedConfig(), {
          entry: { 'main-client': './ClientApp/boot-client.tsx' },
          module: {
              rules: [
                  //{
                  //    test: /\.css$/,
                  //    use: ExtractTextPlugin.extract({ use: isDevBuild ? 'css-loader' : 'css-loader?minimize' })
                  //},
                  {
                      test: /\.scss$/,
                      use: ExtractTextPlugin.extract({
                          use: ['css-loader', 'sass-loader']
                      }),
                  }
              ]
          },
          output: { path: path.join(__dirname, clientBundleOutputDir) },
          plugins: [
              new ExtractTextPlugin('style.css'),
              new webpack.DllReferencePlugin({
                  context: __dirname,
                  manifest: require('./wwwroot/dist/vendor-manifest.json')
              })
          ].concat(isDevBuild ? [
              // Plugins that apply in development builds only
              new webpack.SourceMapDevToolPlugin({
                  filename: '[file].map', // Remove this line if you prefer inline source maps
                  moduleFilenameTemplate: path.relative(clientBundleOutputDir, '[resourcePath]') // Point sourcemap entries to the original file locations on disk
              })
          ] : [
                  // Plugins that apply in production builds only
                  new webpack.optimize.UglifyJsPlugin()
              ])
      });
  
      // Configuration for server-side (prerendering) bundle suitable for running in Node
      const serverBundleConfig = merge(sharedConfig(), {
          resolve: { mainFields: ['main'] },
          entry: { 'main-server': './ClientApp/boot-server.tsx' },
          plugins: [
              new webpack.DllReferencePlugin({
                  context: __dirname,
                  manifest: require('./ClientApp/dist/vendor-manifest.json'),
                  sourceType: 'commonjs2',
                  name: './vendor'
              })
          ],
          output: {
              libraryTarget: 'commonjs',
              path: path.join(__dirname, './ClientApp/dist')
          },
          target: 'node',
          devtool: 'inline-source-map'
      });
  
      return [clientBundleConfig, serverBundleConfig];
  };