<commit_before>import path from 'path'
import webpack from 'webpack'
import WebpackDevServer from 'webpack-dev-server'
import configPassthrough from '../configPassthrough'
import babelConfig from '../babelConfig'
import log from '../log'

const defaultEntry = './src/index.js'
const defaultBundle = './dist/bundle.js'

export default function build (entry = defaultEntry, bundle = defaultBundle, options) {
  log.verbose('entry: %s', entry)
  log.verbose('bundle: %s', bundle)

  const resolvers = {
    fallback: path.resolve(path.join(__dirname, '../../node_modules'))
  }

  const baseBundleConfig = {
    options,
    entry: [
      entry
    ],
    plugins: [
      new webpack.DefinePlugin({
        'process.env': {
          'NODE_ENV': JSON.stringify('production')
        }
      }),
      new webpack.optimize.UglifyJsPlugin({
        compress: {
          warnings: false
        }
      })
    ],
    devtool: 'source-map',
    output: {
      path: path.dirname(path.resolve(bundle)),
      filename: path.basename(bundle)
    },
    module: {
      loaders: [
        {
          test: /\.js$/,
          exclude: /node_modules/,
          loader: 'babel',
          query: babelConfig()
        }
      ]
    },
    resolve: resolvers,
    resolveLoader: resolvers
  }

  if (options.dev) {
    log.debug('applying dev config mutations')

    baseBundleConfig.serverPort = 8080

    baseBundleConfig.entry.unshift(
      'webpack-dev-server/client?http://localhost:8080/'
    )

    baseBundleConfig.plugins.push(
      new webpack.DefinePlugin({
        'process.env': {
          'NODE_ENV': JSON.stringify('development')
        }
      }),
      new webpack.HotModuleReplacementPlugin()
    )
  }

  const bundleConfig = configPassthrough('webpack', baseBundleConfig)
  const compiler = webpack(bundleConfig)

  if (options.dev) {
    const server = new WebpackDevServer(compiler, {<commit_msg>Fix dev / prd plugins setup<commit_after>import path from 'path'
import webpack from 'webpack'
import WebpackDevServer from 'webpack-dev-server'
import configPassthrough from '../configPassthrough'
import babelConfig from '../babelConfig'
import log from '../log'

const defaultEntry = './src/index.js'
const defaultBundle = './dist/bundle.js'

export default function build (entry = defaultEntry, bundle = defaultBundle, options) {
  log.verbose('entry: %s', entry)
  log.verbose('bundle: %s', bundle)

  const resolvers = {
    fallback: path.resolve(path.join(__dirname, '../../node_modules'))
  }

  const baseBundleConfig = {
    options,
    entry: [
      entry
    ],
    devtool: 'source-map',
    output: {
      path: path.dirname(path.resolve(bundle)),
      filename: path.basename(bundle)
    },
    module: {
      loaders: [
        {
          test: /\.js$/,
          exclude: /node_modules/,
          loader: 'babel',
          query: babelConfig()
        }
      ]
    },
    resolve: resolvers,
    resolveLoader: resolvers
  }

  if (options.dev) {
    log.debug('applying dev config mutations')

    baseBundleConfig.serverPort = 8080

    baseBundleConfig.entry.unshift(
      'webpack-dev-server/client?http://localhost:8080/'
    )

    baseBundleConfig.plugins = [
      new webpack.DefinePlugin({
        'process.env': {
          'NODE_ENV': JSON.stringify('development')
        }
      }),
      new webpack.HotModuleReplacementPlugin()
    ]
  } else {
    baseBundleConfig.plugins = [
      new webpack.DefinePlugin({
        'process.env': {
          'NODE_ENV': JSON.stringify('production')
        }
      }),
      new webpack.optimize.UglifyJsPlugin({
        compress: {
          warnings: false
        }
      })
    ]
  }

  const bundleConfig = configPassthrough('webpack', baseBundleConfig)
  const compiler = webpack(bundleConfig)

  if (options.dev) {
    const server = new WebpackDevServer(compiler, {
{'fraction_non_alphanumeric': 0.1279731127197518, 'fraction_numerical': 0.004136504653567736, 'mean_word_length': 2.5013574660633484, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '79976', 'n_tokens_mistral': 1193, 'n_tokens_neox': 1142, 'n_words': 241}