<commit_before>// Based on angular2-webpack-starter: https://github.com/AngularClass/angular2-webpack-starter/tree/1349411df7ced79f2e8486ce7f4aae6ab5e083e0

const webpack = require('webpack');
const helpers = require('./helpers');
const NormalModuleReplacementPlugin = require('webpack/lib/NormalModuleReplacementPlugin');
const ContextReplacementPlugin = require('webpack/lib/ContextReplacementPlugin');
const CommonsChunkPlugin = require('webpack/lib/optimize/CommonsChunkPlugin');
const CheckerPlugin = require('awesome-typescript-loader').CheckerPlugin;
const LoaderOptionsPlugin = require('webpack/lib/LoaderOptionsPlugin');
const DefinePlugin = require('webpack/lib/DefinePlugin');
const NamedModulesPlugin = require('webpack/lib/NamedModulesPlugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const IgnorePlugin = require('webpack/lib/IgnorePlugin');
const ProvidePlugin = require('webpack/lib/ProvidePlugin');
const UglifyJsPlugin = require('webpack/lib/optimize/UglifyJsPlugin');
const V8LazyParseWebpackPlugin = require('v8-lazy-parse-webpack-plugin');
const ngcWebpack = require('ngc-webpack');
const CompressionPlugin = require('compression-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');

const env = process.env.ASPNETCORE_ENVIRONMENT || 'Development';
const isServer = helpers.hasNpmFlag('server') || helpers.hasProcessFlag('SERVER_BUILD');
const isDev = process.env.ASPNETCORE_ENVIRONMENT === 'Production' ? false : true;
const isProd = !isDev;
const isAot = helpers.hasNpmFlag('aot') || helpers.hasProcessFlag('AOT');
const distPath = isServer ? 'serverdist' : 'dist';

const tsLintOptions = {
  // tslint errors are displayed by default as warnings 
  // set emitErrors to true to display them as errors 
  emitErrors: true,

  // tslint does not interrupt the compilation by default 
  // if you want any file with tslint errors to fail 
  // set failOnHint to true 
  failOnHint: false
};

function makeWebpackConfig() {

  console.log('@@@@@@@@@@@@@@@@@@@@@@@@@@@ ' + env + (isAot ? ' (AOT)' : '') + (isServer ? ' (SERVER)' : '') + ' @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@');

  var config = {};

  config.target = isServer ? 'node' : 'web';

  if (isServer) {
    config.devtool = 'inline-source-map';
  } else if (isDev) {
    config.devtool = 'cheap-module-source-map';
  } else {
    config.devtool = 'source-map';
  }

  // Cache generated modules and chunks to improve performance for multiple incremental builds.
  // This is enabled by default in watch mode.
  // You can pass false to disable it.
  //config.cache = false,

  config.entry = {};

  if (isServer) {
    config.entry['main-server'] = './src/main.server.ts';
  }
  else {
    config.entry['polyfills'] = './src/polyfills.browser.ts';
    config.entry['main'] = isAot ? './src/main.browser.aot.ts' : './src/main.browser.ts';
  }

  config.output = {
    path: helpers.root('wwwroot', distPath)
  };

  if (isServer) {
    config.output.filename = '[name].js';
    config.output.libraryTarget = 'commonjs';
  }
  else {
    config.output.filename = '[name].bundle.js';
    config.output.sourceMapFilename = '[file].map';
    config.output.chunkFilename = '[id].chunk.js';
    config.output.publicPath = '/dist/';
    
    if (isDev) {
      config.output.library = 'ac_[name]';
      config.output.libraryTarget = 'var';
    }
  }  

  config.resolve = {

    // An array of extensions that should be used to resolve modules.
    extensions: ['.ts', '.js', '.json'],

    // An array of directory names to be resolved to the current directory
    modules: [helpers.root('src'), helpers.root('node_modules')],

  };

  config.module = {

    rules: [
      {
        enforce: 'pre',
        test: /\.ts$/,
        loader: 'tslint-loader',
        exclude: /(node_modules)/,
      },

      // Typescript loader support for .ts and Angular 2 async routes via .async.ts
      // Replace templateUrl and stylesUrl with require()
      {
        test: /\.ts$/,
        use: [
          'awesome-typescript-loader?{configFileName: "tsconfig.webpack.json"}',
          'angular2-template-loader',
          {
            loader: 'ng-router-loader',
            options: {
              loader: 'async-system',
              genDir: 'compiled',
              aot: isAot
            }
          }
        ],
        exclude: [/\.(spec|e2e)\.ts$/]
      },

      // Json loader support for *.json files.
      {
        test: /\.json$/,
        use: 'json-loader'
      },

      // to string and css loader support for *.css files (from Angular components)
      // Returns file content as string
      {
        test: /\.css$/,
        use: ['to-string-loader', 'css-loader'],
        exclude: [helpers.root('src', 'styles')]
      },

      // to string and sass loader support for *.scss files (from Angular components)
      // Returns compiled css content as string
      {
        test: /\.scss$/,
        use: ['to-string-loader', 'css-loader', 'sass-loader'],
        exclude: [helpers.root('src', 'styles')]
      },

      // to string and css loader support for *.css files (from Angular components)
      // Returns file content as string
      {
        test: /\.css$/,
        loader: isServer ? ('to-string-loader!css-loader') : (isDev ? 'style-loader!css-loader' : ExtractTextPlugin.extract({ fallbackLoader: 'style-loader', loader: 'css-loader' })),
        include: [helpers.root('src', 'styles')]
      },

      // To string and sass loader support for *.scss files (from Angular components)
      // Returns compiled css content as string
      {
        test: /\.scss$/,
        loader: isServer ? ('to-string-loader!css-loader!sass-loader') : (isDev ? 'style-loader!css-loader!sass-loader' : ExtractTextPlugin.extract({
          fallbackLoader: 'style-loader',
          loader: 'css-loader!sass-loader'
        })),
        include: [helpers.root('src', 'styles')]
      },

      // Raw loader support for *.html. Returns file content as string
      {
        test: /\.html$/,
        use: 'raw-loader'
      },

      // File loader for supporting images, for example, in CSS files.
      {
        test: /\.(jpg|png|gif)$/,
        use: 'file-loader'
      },

    ],

  };

  config.plugins = [   
    new CleanWebpackPlugin([helpers.root('wwwroot', distPath), helpers.root('compiled')], {
      verbose: true
    }),

    // NOTE: when adding more properties make sure you include them in custom-typings.d.ts
    new DefinePlugin({
      'ENV': JSON.stringify(process.env.ASPNETCORE_ENVIRONMENT),
      'process.env': {
        'ENV': JSON.stringify(process.env.ASPNETCORE_ENVIRONMENT),
        'NODE_ENV': JSON.stringify(process.env.ASPNETCORE_ENVIRONMENT)<commit_msg>Update log message. Turned off verbosity of the CleanWebpackPlugin (the messages are shown as errors in .NET Core output).<commit_after>// Based on angular2-webpack-starter: https://github.com/AngularClass/angular2-webpack-starter/tree/1349411df7ced79f2e8486ce7f4aae6ab5e083e0

const webpack = require('webpack');
const helpers = require('./helpers');
const NormalModuleReplacementPlugin = require('webpack/lib/NormalModuleReplacementPlugin');
const ContextReplacementPlugin = require('webpack/lib/ContextReplacementPlugin');
const CommonsChunkPlugin = require('webpack/lib/optimize/CommonsChunkPlugin');
const CheckerPlugin = require('awesome-typescript-loader').CheckerPlugin;
const LoaderOptionsPlugin = require('webpack/lib/LoaderOptionsPlugin');
const DefinePlugin = require('webpack/lib/DefinePlugin');
const NamedModulesPlugin = require('webpack/lib/NamedModulesPlugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const IgnorePlugin = require('webpack/lib/IgnorePlugin');
const ProvidePlugin = require('webpack/lib/ProvidePlugin');
const UglifyJsPlugin = require('webpack/lib/optimize/UglifyJsPlugin');
const V8LazyParseWebpackPlugin = require('v8-lazy-parse-webpack-plugin');
const ngcWebpack = require('ngc-webpack');
const CompressionPlugin = require('compression-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');

const env = process.env.ASPNETCORE_ENVIRONMENT || 'Development';
const isServer = helpers.hasNpmFlag('server') || helpers.hasProcessFlag('SERVER_BUILD');
const isDev = process.env.ASPNETCORE_ENVIRONMENT === 'Production' ? false : true;
const isProd = !isDev;
const isAot = helpers.hasNpmFlag('aot') || helpers.hasProcessFlag('AOT');
const distPath = isServer ? 'serverdist' : 'dist';

const tsLintOptions = {
  // tslint errors are displayed by default as warnings 
  // set emitErrors to true to display them as errors 
  emitErrors: true,

  // tslint does not interrupt the compilation by default 
  // if you want any file with tslint errors to fail 
  // set failOnHint to true 
  failOnHint: false
};

function makeWebpackConfig() {

  console.log('@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@');
  console.log((isServer ? 'SERVER' : 'BROWSER') + ' | ' + env.toUpperCase() + ' | ' + (isAot ? 'AOT' : 'JIT'));
  console.log('@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@');

  var config = {};

  config.target = isServer ? 'node' : 'web';

  if (isServer) {
    config.devtool = 'inline-source-map';
  } else if (isDev) {
    config.devtool = 'cheap-module-source-map';
  } else {
    config.devtool = 'source-map';
  }

  // Cache generated modules and chunks to improve performance for multiple incremental builds.
  // This is enabled by default in watch mode.
  // You can pass false to disable it.
  //config.cache = false,

  config.entry = {};

  if (isServer) {
    config.entry['main-server'] = './src/main.server.ts';
  }
  else {
    config.entry['polyfills'] = './src/polyfills.browser.ts';
    config.entry['main'] = isAot ? './src/main.browser.aot.ts' : './src/main.browser.ts';
  }

  config.output = {
    path: helpers.root('wwwroot', distPath)
  };

  if (isServer) {
    config.output.filename = '[name].js';
    config.output.libraryTarget = 'commonjs';
  }
  else {
    config.output.filename = '[name].bundle.js';
    config.output.sourceMapFilename = '[file].map';
    config.output.chunkFilename = '[id].chunk.js';
    config.output.publicPath = '/dist/';
    
    if (isDev) {
      config.output.library = 'ac_[name]';
      config.output.libraryTarget = 'var';
    }
  }  

  config.resolve = {

    // An array of extensions that should be used to resolve modules.
    extensions: ['.ts', '.js', '.json'],

    // An array of directory names to be resolved to the current directory
    modules: [helpers.root('src'), helpers.root('node_modules')],

  };

  config.module = {

    rules: [
      {
        enforce: 'pre',
        test: /\.ts$/,
        loader: 'tslint-loader',
        exclude: /(node_modules)/,
      },

      // Typescript loader support for .ts and Angular 2 async routes via .async.ts
      // Replace templateUrl and stylesUrl with require()
      {
        test: /\.ts$/,
        use: [
          'awesome-typescript-loader?{configFileName: "tsconfig.webpack.json"}',
          'angular2-template-loader',
          {
            loader: 'ng-router-loader',
            options: {
              loader: 'async-system',
              genDir: 'compiled',
              aot: isAot
            }
          }
        ],
        exclude: [/\.(spec|e2e)\.ts$/]
      },

      // Json loader support for *.json files.
      {
        test: /\.json$/,
        use: 'json-loader'
      },

      // to string and css loader support for *.css files (from Angular components)
      // Returns file content as string
      {
        test: /\.css$/,
        use: ['to-string-loader', 'css-loader'],
        exclude: [helpers.root('src', 'styles')]
      },

      // to string and sass loader support for *.scss files (from Angular components)
      // Returns compiled css content as string
      {
        test: /\.scss$/,
        use: ['to-string-loader', 'css-loader', 'sass-loader'],
        exclude: [helpers.root('src', 'styles')]
      },

      // to string and css loader support for *.css files (from Angular components)
      // Returns file content as string
      {
        test: /\.css$/,
        loader: isServer ? ('to-string-loader!css-loader') : (isDev ? 'style-loader!css-loader' : ExtractTextPlugin.extract({ fallbackLoader: 'style-loader', loader: 'css-loader' })),
        include: [helpers.root('src', 'styles')]
      },

      // To string and sass loader support for *.scss files (from Angular components)
      // Returns compiled css content as string
      {
        test: /\.scss$/,
        loader: isServer ? ('to-string-loader!css-loader!sass-loader') : (isDev ? 'style-loader!css-loader!sass-loader' : ExtractTextPlugin.extract({
          fallbackLoader: 'style-loader',
          loader: 'css-loader!sass-loader'
        })),
        include: [helpers.root('src', 'styles')]
      },

      // Raw loader support for *.html. Returns file content as string
      {
        test: /\.html$/,
        use: 'raw-loader'
      },

      // File loader for supporting images, for example, in CSS files.
      {
        test: /\.(jpg|png|gif)$/,
        use: 'file-loader'
      },

    ],

  };

  config.plugins = [   
    new CleanWebpackPlugin([helpers.root('wwwroot', distPath), helpers.root('compiled')], {
      verbose: false
    }),

    // NOTE: when adding more properties make sure you include them in custom-typings.d.ts
    new DefinePlugin({
      'ENV': JSON.stringify(process.env.ASPNETCORE_ENVIRONMENT),
      'process.env': {
        'ENV': JSON.stringify(process.env.ASPNETCORE_ENVIRONMENT),
        'NODE_ENV': JSON.stringify(process.env.ASPNETCORE_ENVIRONMENT)
{'fraction_non_alphanumeric': 0.15858453473132372, 'fraction_numerical': 0.00436871996505024, 'mean_word_length': 2.911990885787525, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4694090', 'n_tokens_mistral': 4290, 'n_tokens_neox': 4137, 'n_words': 976}