<commit_before>'use strict';

const path = require('path')
    , webpack = require('webpack')
    , merge = require('webpack-merge')
    , HtmlWebpackPlugin = require('html-webpack-plugin')
    , projectConfig = require('./config');

const
    // Environment
      ENV = projectConfig.env
    , API = projectConfig.api

    // Module folders
    , VENDORS = ['node_modules', 'bower_components']
    , VENDOR_RE = new RegExp(VENDORS.join('|'))

    // Input and output folders
    , SRC_PATH = projectConfig.app
    , TEST_PATH = projectConfig.test
    , BUILD_PATH = projectConfig.dist

    // File names
    , INDEX = 'index'
    , MAIN = 'main'
    , TEST = 'app'
    , VENDOR = 'vendor';

// Check if module is vendor, for chunking
const isVendor = (module) => {
  var r = module.userRequest;
  return typeof r === 'string' && r.match(VENDOR_RE);
}

var config = {
  // What file to start at
  entry: [path.join(SRC_PATH, `${MAIN}.coffee`)],

  // Where to output
  output: {
    path: BUILD_PATH,
    publicPath: '/',
    filename: '[name].js',
  },

  // Where to load modules from
  resolve: {
    root: SRC_PATH,
    modulesDirectories: VENDORS,
    extensions: ['', '.coffee', '.l.styl', '.styl', '.js', '.css']
  },

  // Stylus options
  stylus: {
    use: [require('nib')()],
    import: ['~nib/lib/nib/index.styl'],
    preferPathResolver: 'webpack',
  },

  // Coffeelint options
  coffeelint: {
    configFile: 'coffeelint.json',
  },

  // Stylint options
  stylint: {
    config: 'stylint.json',
  },

  // Module loading options
  module: {
    // Linters, etc
    preLoaders: [
      { // Coffeelint
        test: /\.coffee$/,
        loader: 'coffee-lint',
        exclude: VENDOR_RE,
      },
      { // Stylint
        test: /\.styl/,
        loader: 'stylint',
        exclude: VENDOR_RE,
      },
    ],

    // Files to load
    loaders: [
      { // Pug
        test: /\.pug$/,
        loaders: ['pug-html'],
      },
      { // Coffeescript
        test: /\.coffee$/,
        loaders: ['coffee'],
      },
      { // Stylus (locally scoped)
        test: /\.l.styl$/,
        loaders: ['style', 'css?modules', 'stylus'],
      },
      { // Stylus (globally scoped)
        test: /\.styl$/,
        exclude: /\.l.styl$/,
        loaders: ['style', 'css', 'stylus'],
      },
      { // Plain CSS
        test: /\.css$/,
        loaders: ['style', 'css'],
      },
      { // Media
        test: /\.(png|jpe?g|gif|svg|woff2?|eot|ttf)$/,
        loaders: ['url'],
      },
    ],
  },

  plugins: [
    // Generate HTML
    new HtmlWebpackPlugin({
      template: path.join(SRC_PATH, `${INDEX}.pug`),
    }),

    // Separate vendor bundle
    new webpack.optimize.CommonsChunkPlugin({
      name: VENDOR,
      minChunks: isVendor,
    }),
  ],
};

const devServerOpts = {
  // Public serving
  host: '0.0.0.0',

  // Use defined port
  port: projectConfig.ports.app,

  // No iframe
  inline: true,

  // Show progress
  progress: true,

  // Hot reloading
  hot: true,

  // Allow routing
  historyApiFallback: true,

  // Display options
  stats: {
    // Do not show list of hundreds of files included in a bundle
    chunkModules: false,

    // Pretty colors
    colors: true,
  },
};

// Options based on environment
switch (ENV) {
  case 'dev': // Development
    console.log('Running development server...');

    config = merge(config, {
      // Source maps
      devtool: 'cheap-module-eval-source-map',

      // -- Hot loading --

      module: {
        loaders: [
          {
            test: /\.coffee$/,
            loaders: ['react-hot-loader/webpack'],
          },
        ],
      },

      plugins: [
        // Devevelopment environment variable
        new webpack.DefinePlugin({
          'process.env': {
            'NODE_ENV': '"development"',
          },
        }),

        new webpack.HotModuleReplacementPlugin(),
      ],

      devServer: devServerOpts,
    });
    break;

  case 'build': // Production<commit_msg>fix local style regex<commit_after>'use strict';

const path = require('path')
    , webpack = require('webpack')
    , merge = require('webpack-merge')
    , HtmlWebpackPlugin = require('html-webpack-plugin')
    , projectConfig = require('./config');

const
    // Environment
      ENV = projectConfig.env
    , API = projectConfig.api

    // Module folders
    , VENDORS = ['node_modules', 'bower_components']
    , VENDOR_RE = new RegExp(VENDORS.join('|'))

    // Input and output folders
    , SRC_PATH = projectConfig.app
    , TEST_PATH = projectConfig.test
    , BUILD_PATH = projectConfig.dist

    // File names
    , INDEX = 'index'
    , MAIN = 'main'
    , TEST = 'app'
    , VENDOR = 'vendor';

// Check if module is vendor, for chunking
const isVendor = (module) => {
  var r = module.userRequest;
  return typeof r === 'string' && r.match(VENDOR_RE);
}

var config = {
  // What file to start at
  entry: [path.join(SRC_PATH, `${MAIN}.coffee`)],

  // Where to output
  output: {
    path: BUILD_PATH,
    publicPath: '/',
    filename: '[name].js',
  },

  // Where to load modules from
  resolve: {
    root: SRC_PATH,
    modulesDirectories: VENDORS,
    extensions: ['', '.coffee', '.l.styl', '.styl', '.js', '.css']
  },

  // Stylus options
  stylus: {
    use: [require('nib')()],
    import: ['~nib/lib/nib/index.styl'],
    preferPathResolver: 'webpack',
  },

  // Coffeelint options
  coffeelint: {
    configFile: 'coffeelint.json',
  },

  // Stylint options
  stylint: {
    config: 'stylint.json',
  },

  // Module loading options
  module: {
    // Linters, etc
    preLoaders: [
      { // Coffeelint
        test: /\.coffee$/,
        loader: 'coffee-lint',
        exclude: VENDOR_RE,
      },
      { // Stylint
        test: /\.styl/,
        loader: 'stylint',
        exclude: VENDOR_RE,
      },
    ],

    // Files to load
    loaders: [
      { // Pug
        test: /\.pug$/,
        loaders: ['pug-html'],
      },
      { // Coffeescript
        test: /\.coffee$/,
        loaders: ['coffee'],
      },
      { // Stylus (locally scoped)
        test: /\.l\.styl$/,
        loaders: ['style', 'css?modules', 'stylus'],
      },
      { // Stylus (globally scoped)
        test: /\.styl$/,
        exclude: /\.l\.styl$/,
        loaders: ['style', 'css', 'stylus'],
      },
      { // Plain CSS
        test: /\.css$/,
        loaders: ['style', 'css'],
      },
      { // Media
        test: /\.(png|jpe?g|gif|svg|woff2?|eot|ttf)$/,
        loaders: ['url'],
      },
    ],
  },

  plugins: [
    // Generate HTML
    new HtmlWebpackPlugin({
      template: path.join(SRC_PATH, `${INDEX}.pug`),
    }),

    // Separate vendor bundle
    new webpack.optimize.CommonsChunkPlugin({
      name: VENDOR,
      minChunks: isVendor,
    }),
  ],
};

const devServerOpts = {
  // Public serving
  host: '0.0.0.0',

  // Use defined port
  port: projectConfig.ports.app,

  // No iframe
  inline: true,

  // Show progress
  progress: true,

  // Hot reloading
  hot: true,

  // Allow routing
  historyApiFallback: true,

  // Display options
  stats: {
    // Do not show list of hundreds of files included in a bundle
    chunkModules: false,

    // Pretty colors
    colors: true,
  },
};

// Options based on environment
switch (ENV) {
  case 'dev': // Development
    console.log('Running development server...');
    config = merge(config, {
      // Source maps
      devtool: 'cheap-module-eval-source-map',

      // -- Hot loading --

      module: {
        loaders: [
          {
            test: /\.coffee$/,
            loaders: ['react-hot-loader/webpack'],
          },
        ],
      },

      plugins: [
        // Devevelopment environment variable
        new webpack.DefinePlugin({
          'process.env': {
            'NODE_ENV': '"development"',
          },
        }),

        new webpack.HotModuleReplacementPlugin(),
      ],

      devServer: devServerOpts,
    });
    break;

  case 'build': // Production
{'fraction_non_alphanumeric': 0.16296296296296298, 'fraction_numerical': 0.0012554927809165098, 'mean_word_length': 1.9147457006952067, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '2178304', 'n_tokens_mistral': 2727, 'n_tokens_neox': 2641, 'n_words': 590}