<commit_before>var path = require('path');

function _includePaths (basePath) {
  if (basePath) {
    return [
      basePath + '/app',
      basePath + '/candela.js',
      basePath + '/components',
      basePath + '/shim',
      basePath + '/test',
      basePath + '/util',
      basePath + '/VisComponent'
    ];
  } else {
    return [
      /\/node_modules\/candela\//
    ]
  }
}

function addNMPath(packages, paths) {
  if (!Array.isArray(packages)) {
    packages = [packages];
  }

  return packages.map(function (package) {
    return new RegExp('/node_modules/' + package + '/')
  }).concat(paths);
}

module.exports = function (config, basePath) {
  var includePaths = _includePaths(basePath);

  // Install empty module and module.loaders entries if missing.
  config.module = config.module || {};
  config.module.loaders = config.module.loaders || [];

  // Prepend the Candela loaders.
  config.module.loaders = [
    {
      test: /\.js$/,
      loader: 'babel-loader',
      query: {
        presets: ['es2015']
      },
      include: includePaths
    },
    {
      test: /\.jpe?g$|\.gif$|\.png$|\.woff$|\.wav$|\.mp3$|\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$|\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
      loader: 'url-loader',
      include: addNMPath(['font-awesome', 'bootstrap'], includePaths)
    },
    {
      test: /\.csv$/,
      loader: 'raw-loader',
      include: includePaths<commit_msg>build(webpack): exclude existing loaders from affecting node_modules/candela<commit_after>var path = require('path');

function _includePaths (basePath) {
  if (basePath) {
    return [
      basePath + '/app',
      basePath + '/candela.js',
      basePath + '/components',
      basePath + '/shim',
      basePath + '/test',
      basePath + '/util',
      basePath + '/VisComponent'
    ];
  } else {
    return [
      /\/node_modules\/candela\//
    ]
  }
}

function addNMPath(packages, paths) {
  if (!Array.isArray(packages)) {
    packages = [packages];
  }

  return packages.map(function (package) {
    return new RegExp('/node_modules/' + package + '/')
  }).concat(paths);
}

module.exports = function (config, basePath, options) {
  var includePaths = _includePaths(basePath);

  options = options || {};

  // By default, exclude the existing loaders from affecting
  // node_modules/candela. This prevents double application of loaders if they
  // are specified in the client project without any include or exclude
  // directives.
  var exclude = options.excludeCandelaNM === undefined || options.excludeCandelaNM;

  // Install empty module and module.loaders entries if missing.
  config.module = config.module || {};
  config.module.loaders = config.module.loaders || [];

  // Exclude the base paths from having existing loaders applied to them.
  if (exclude) {
    config.modules.loaders = config.modules.loaders || [];
    config.modules.loaders.forEach(function (loader) {
      loader.exclude = (loader.exclude || []).concat(includePaths);
    });
  }

  // Prepend the Candela loaders.
  config.module.loaders = [
    {
      test: /\.js$/,
      loader: 'babel-loader',
      query: {
        presets: ['es2015']
      },
      include: includePaths
    },
    {
      test: /\.jpe?g$|\.gif$|\.png$|\.woff$|\.wav$|\.mp3$|\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$|\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
      loader: 'url-loader',
      include: addNMPath(['font-awesome', 'bootstrap'], includePaths)
    },
    {
      test: /\.csv$/,
      loader: 'raw-loader',
      include: includePaths
{'fraction_non_alphanumeric': 0.1811512415349887, 'fraction_numerical': 0.010158013544018058, 'mean_word_length': 2.609979633401222, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '5651388', 'n_tokens_mistral': 1203, 'n_tokens_neox': 1171, 'n_words': 238}