<commit_before>const webpack = require('webpack');
const {resolve} = require('path');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const PACKAGE = require('./package.json');
const version = PACKAGE.version;

const isProduction = process.env.NODE_ENV === 'production';

const internalDepsFilter = (module, count) => {
  return module.resource && /cartodb.js|deep-insights.js/.test(module.resource);
};

module.exports = env => {
  return {
    entry: {
      public_editor: './lib/assets/core/javascripts/cartodb3/public_editor.js',
      dataset: './lib/assets/core/javascripts/cartodb3/dataset.js',
      editor: './lib/assets/core/javascripts/cartodb3/editor.js'
    },
    output: {
      filename: `${version}/[name].[chunkhash].js`,
      path: resolve(__dirname, 'dist')
    },
    devtool: isProduction ? 'source-map' : 'eval-source-map',
    plugins: [
      isProduction ? undefined : new BundleAnalyzerPlugin({
        analyzerMode: 'static'
      }),

      new webpack.optimize.CommonsChunkPlugin({
        name: 'vendor',
        minChunks: function (module) {
          // this assumes your vendor imports exist in the node_modules directory
          return module.context && module.context.indexOf('node_modules') !== -1;
        }
      }),

      new webpack.optimize.CommonsChunkPlugin({
        name: 'common',
        minChunks: internalDepsFilter
      })
    ].filter(p => !!p), // undefined is not a valid plugin, so filter undefined values here
    module: {
      rules: [
        {
          test: /\.tpl$/,
          use: 'tpl-loader'
        },
        {
          test: /\.mustache$/,
          use: 'raw-loader'
        }
      ]
    },

    node: {
      fs: 'empty' // This fixes the error Module not found: Error: Can't resolve 'fs'
    }
  };
};
<commit_msg>Split code in entry points, vendor for every entry point and a common chunck for all of them.<commit_after>const webpack = require('webpack');
const {resolve} = require('path');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const PACKAGE = require('./package.json');
const version = PACKAGE.version;

const isProduction = process.env.NODE_ENV === 'production';

const isVendor = (module, count) => {
  const userRequest = module.userRequest;
  return userRequest && userRequest.indexOf('node_modules') >= 0;
};

const entryPoints = {
  public_editor: './lib/assets/core/javascripts/cartodb3/public_editor.js',
  dataset: './lib/assets/core/javascripts/cartodb3/dataset.js',
  editor: './lib/assets/core/javascripts/cartodb3/editor.js'
};

module.exports = env => {
  return {
    entry: entryPoints,
    output: {
      filename: `${version}/[name].[chunkhash].js`,
      path: resolve(__dirname, 'dist')
    },
    devtool: isProduction ? 'source-map' : 'eval-source-map',
    plugins: [
      isProduction ? undefined : new BundleAnalyzerPlugin({
        analyzerMode: 'static'
      })
    ].concat(
      // For each entry point, we generate the vendor file
      Object.keys(entryPoints)
        .map(entry => new webpack.optimize.CommonsChunkPlugin({
          name: `${entry}_vendor`,
          chunks: [entry],
          minChunks: isVendor
        }))
    )
    .concat([
      new webpack.optimize.CommonsChunkPlugin({
        name: 'common',
        chunks: Object.keys(entryPoints).map(n => `${n}_vendor`),
        minChunks: (module, count) => {
          return count >= Object.keys(entryPoints).length && isVendor(module);
        }
      })
    ])
    .concat(
        // Extract common chuncks in the 3 entries
        new webpack.optimize.CommonsChunkPlugin({
          children: true,
          minChunks: Object.keys(entryPoints).length
        })
      )
    .filter(p => !!p), // undefined is not a valid plugin, so filter undefined values here
    module: {
      rules: [
        {
          test: /\.tpl$/,
          use: 'tpl-loader'
        },
        {
          test: /\.mustache$/,
          use: 'raw-loader'
        }
      ]
    },

    node: {
      fs: 'empty' // This fixes the error Module not found: Error: Can't resolve 'fs'
    }
  };
};

{'fraction_non_alphanumeric': 0.1430635838150289, 'fraction_numerical': 0.002167630057803468, 'mean_word_length': 2.510566356720203, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, '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': '7203376', 'n_tokens_mistral': 1259, 'n_tokens_neox': 1233, 'n_words': 280}