<commit_before>'use strict';

const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const isProductionMode = process.env.NODE_ENV == 'production';

const path = require('path');

const webpackConfig = {
  name: 'client',
  target: 'web',
  entry: {
    app: [
      './src/app.js'
    ]
  },
  output: {
    filename: '[name].js',
    path: 'dist',
    publicPath: '/'
  },
  plugins: [
    // new webpack.DefinePlugin(config.get('globals')),
    new webpack.optimize.OccurenceOrderPlugin(),
    new webpack.optimize.DedupePlugin(),
    new HtmlWebpackPlugin({
      template: './src/index.html',
      hash: true,
      filename: 'index.html',
      inject: 'body'
    }),
    new CopyWebpackPlugin([
      {
        from: './src/ui/common/images',
        to: 'images'
      }
    ])
  ],
  // these break for node 5.3+ when building WS stuff
  node: {
    fs: 'empty',
    tls: 'empty'
  },
  resolve: {
    extensions: ['', '.js', '.jsx'],
    alias: {
      system: __dirname + '/src/system',
      services: __dirname + '/src/services'
    }
  },
  eslint: {
    configFile: './.eslintrc'
  },
  module: {
    // this breaks in node 5.3+ as it tries to parse the README.md for node-bindings
    noParse: /\/bindings\//,
    preLoaders: [
      {test: /\.js$/, loader: 'eslint-loader', exclude: /node_modules/}
    ],
    loaders: [
      {
        test: /\.(js|jsx)$/,
        exclude: /node_modules/,
        loader: 'babel',
        query: {
          stage: 0,
          optional: ['runtime'],
          env: {
            development: {
              plugins: ['react-transform'],
              extra: {
                'react-transform': {
                  transforms: [{
                    transform: 'react-transform-catch-errors',
                    imports: ['react', 'redbox-react']
                  }]
                }
              }
            }
          }
        }
      },
      {
        test: /\.scss$/,
        loaders: [
          'style-loader',
          'css-loader',
          'autoprefixer?browsers=last 2 version',
          'sass-loader'
        ]
      },
      {
        test: /\.json$/,
        loader: 'json-loader'
      },
      {
        test: /\.woff(\?.*)?$/,
        loader: 'url-loader?prefix=fonts/&name=fonts/[name].[ext]&limit=10000&mimetype=application/font-woff'
      },
      {
        test: /\.woff2(\?.*)?$/,
        loader: 'url-loader?prefix=fonts/&name=fonts/[name].[ext]&limit=10000&mimetype=application/font-woff2'
      },
      {
        test: /\.ttf(\?.*)?$/,
        loader: 'url-loader?prefix=fonts/&name=fonts/[name].[ext]&limit=10000&mimetype=application/octet-stream'
      },
      {
        test: /\.eot(\?.*)?$/, loader: 'file-loader?prefix=fonts/&name=fonts/[name].[ext]'
      },
      {
        test: /\.svg(\?.*)?$/,
        loader: 'url-loader?prefix=fonts/&name=fonts/[name].[ext]&limit=10000&mimetype=image/svg+xml'
      }
    ]
  },
  sassLoader: {
    includePaths: './src/**/*.scss'
  }
};

if (isProductionMode){
  webpackConfig.module.loaders = webpackConfig.module.loaders.map(function(loader){
    if (/css/.test(loader.test)){
      var first = loader.loaders[0];
      var rest = loader.loaders.slice(1, loader.loaders.length);
      loader.loader = ExtractTextPlugin.extract(first, rest.join('!'));
      delete loader.loaders;
    }
    return loader;
  });
  webpackConfig.plugins.push(
    new ExtractTextPlugin('[name].[contenthash].css'),
    new webpack.optimize.UglifyJsPlugin({
      compress: {
        'unused': true,
        'dead_code': true
      }
    })
  );
} else {
  webpackConfig.devServer = {
    port: 3000,
    contentBase: path.join(process.cwd(), 'src'),
    historyApiFallback: true,
    stats: {
      colors: true
    },
    noInfo: false,
    quiet: false,
    hot: true
  };
  webpackConfig.devtool = 'source-map';
  webpackConfig.entry.app.push(
    'webpack-dev-server/client?http://0.0.0.0:3000/',
    'webpack/hot/dev-server'
  );
  webpackConfig.plugins.push(
    new webpack.HotModuleReplacementPlugin(),
    new webpack.NoErrorsPlugin()
  );
  // We need to apply the react-transform HMR plugin to the Babel configuration,
  // but _only_ when ModuleReplacement is enabled. Putting this in the default development
  // configuration will break other tasks such as test:unit because Webpack
  // HMR is not enabled there, and these transforms require it.
  webpackConfig.module.loaders = webpackConfig.module.loaders.map(loader =>{
    if (/js(?!on)/.test(loader.test)){
      loader.query.env.development.extra['react-transform'].transforms.push({
        transform: 'react-transform-hmr',
        imports: ['react'],
        locals: ['module']
      });
    }
    return loader;
  });
}

module.exports = webpackConfig;
<commit_msg>build now produces vendor.js as well as app.js, allowing for some caching<commit_after>'use strict';

const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const isProductionMode = process.env.NODE_ENV == 'production';

const path = require('path');

const webpackConfig = {
  name: 'client',
  target: 'web',
  entry: {
    app: [
      './src/app.js'
    ]
  },
  output: {
    filename: '[name].js',
    path: 'dist',
    publicPath: '/'
  },
  plugins: [
    // new webpack.DefinePlugin(config.get('globals')),
    new webpack.optimize.OccurenceOrderPlugin(),
    new webpack.optimize.DedupePlugin(),
    new HtmlWebpackPlugin({
      template: './src/index.html',
      hash: true,
      filename: 'index.html',
      inject: 'body'
    }),
    new CopyWebpackPlugin([
      {
        from: './src/ui/common/images',
        to: 'images'
      }
    ]),
    new webpack.optimize.CommonsChunkPlugin(/* chunkName= */'vendor', /* filename= */'vendor.js', function (module, count) {
      return module.resource && module.resource.indexOf('node_modules') !== -1;
    })
  ],
  // these break for node 5.3+ when building WS stuff
  node: {
    fs: 'empty',
    tls: 'empty'
  },
  resolve: {
    extensions: ['', '.js', '.jsx'],
    alias: {
      system: __dirname + '/src/system',
      services: __dirname + '/src/services'
    }
  },
  eslint: {
    configFile: './.eslintrc'
  },
  module: {
    // this breaks in node 5.3+ as it tries to parse the README.md for node-bindings
    noParse: /\/bindings\//,
    preLoaders: [
      {test: /\.js$/, loader: 'eslint-loader', exclude: /node_modules/}
    ],
    loaders: [
      {
        test: /\.(js|jsx)$/,
        exclude: /node_modules/,
        loader: 'babel',
        query: {
          stage: 0,
          optional: ['runtime'],
          env: {
            development: {
              plugins: ['react-transform'],
              extra: {
                'react-transform': {
                  transforms: [{
                    transform: 'react-transform-catch-errors',
                    imports: ['react', 'redbox-react']
                  }]
                }
              }
            }
          }
        }
      },
      {
        test: /\.scss$/,
        loaders: [
          'style-loader',
          'css-loader',
          'autoprefixer?browsers=last 2 version',
          'sass-loader'
        ]
      },
      {
        test: /\.json$/,
        loader: 'json-loader'
      },
      {
        test: /\.woff(\?.*)?$/,
        loader: 'url-loader?prefix=fonts/&name=fonts/[name].[ext]&limit=10000&mimetype=application/font-woff'
      },
      {
        test: /\.woff2(\?.*)?$/,
        loader: 'url-loader?prefix=fonts/&name=fonts/[name].[ext]&limit=10000&mimetype=application/font-woff2'
      },
      {
        test: /\.ttf(\?.*)?$/,
        loader: 'url-loader?prefix=fonts/&name=fonts/[name].[ext]&limit=10000&mimetype=application/octet-stream'
      },
      {
        test: /\.eot(\?.*)?$/, loader: 'file-loader?prefix=fonts/&name=fonts/[name].[ext]'
      },
      {
        test: /\.svg(\?.*)?$/,
        loader: 'url-loader?prefix=fonts/&name=fonts/[name].[ext]&limit=10000&mimetype=image/svg+xml'
      }
    ]
  },
  sassLoader: {
    includePaths: './src/**/*.scss'
  }
};

if (isProductionMode){
  webpackConfig.module.loaders = webpackConfig.module.loaders.map(function(loader){
    if (/css/.test(loader.test)){
      var first = loader.loaders[0];
      var rest = loader.loaders.slice(1, loader.loaders.length);
      loader.loader = ExtractTextPlugin.extract(first, rest.join('!'));
      delete loader.loaders;
    }
    return loader;
  });
  webpackConfig.plugins.push(
    new ExtractTextPlugin('[name].[contenthash].css'),
    new webpack.optimize.UglifyJsPlugin({
      compress: {
        'unused': true,
        'dead_code': true
      }
    })
  );
} else {
  webpackConfig.devServer = {
    port: 3000,
    contentBase: path.join(process.cwd(), 'src'),
    historyApiFallback: true,
    stats: {
      colors: true
    },
    noInfo: false,
    quiet: false,
    hot: true
  };
  webpackConfig.devtool = 'source-map';
  webpackConfig.entry.app.push(
    'webpack-dev-server/client?http://0.0.0.0:3000/',
    'webpack/hot/dev-server'
  );
  webpackConfig.plugins.push(
    new webpack.HotModuleReplacementPlugin(),
    new webpack.NoErrorsPlugin()
  );
  // We need to apply the react-transform HMR plugin to the Babel configuration,
  // but _only_ when ModuleReplacement is enabled. Putting this in the default development
  // configuration will break other tasks such as test:unit because Webpack
  // HMR is not enabled there, and these transforms require it.
  webpackConfig.module.loaders = webpackConfig.module.loaders.map(loader =>{
    if (/js(?!on)/.test(loader.test)){
      loader.query.env.development.extra['react-transform'].transforms.push({
        transform: 'react-transform-hmr',
        imports: ['react'],
        locals: ['module']
      });
    }
    return loader;
  });
}

module.exports = webpackConfig;

{'fraction_non_alphanumeric': 0.16628814061419966, 'fraction_numerical': 0.008393403772094401, 'mean_word_length': 2.2, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1978848', 'n_tokens_mistral': 3403, 'n_tokens_neox': 3238, 'n_words': 600}