<commit_before>import CleanWebpackPlugin from 'clean-webpack-plugin'
import merge from 'webpack-merge'
import path from 'path'
import webpack, { DefinePlugin, HotModuleReplacementPlugin, NoErrorsPlugin } from 'webpack'
import WebpackMd5Hash from 'webpack-md5-hash'

import actions from '../actions'
import fileExtensions from '../file-extensions'

import buildLibraryConfig from './build-library-config'
import buildPagesConfig from './build-pages-config'
import buildLoadersConfig from './loaders'

/**
 * Takes a saguiConfig object and construct a webpack configuration object
 * It support two different types of archetypes; pages and libraries
 *
 * @return ready to use webpack configuration as an array
 */
export default (saguiConfig = {}) => {
  const { pages = [], libraries = [], ...sharedSaguiConfig } = saguiConfig

  const sharedWebpackConfig = merge.smart(
    buildSharedWebpackConfig(sharedSaguiConfig),
    buildLoadersConfig(sharedSaguiConfig),
    sharedSaguiConfig.webpack
  )

  return [
    ...(pages.length > 0 ? [buildPagesConfig(pages, sharedSaguiConfig)] : []),
    ...libraries.map((libraryConfig) => buildLibraryConfig(libraryConfig, sharedSaguiConfig))
  ].map((entryPointWebpackConfig) => merge.smart(
    sharedWebpackConfig,
    entryPointWebpackConfig
  ))
}

const buildSharedWebpackConfig = (saguiConfig) => {
  const { action, projectPath, saguiPath, watch, optimize } = saguiConfig

  const projectSourcePath = path.join(projectPath, 'src')

  return {
    context: projectSourcePath,

    devtool: action === actions.BUILD ? 'source-map' : 'inline-source-map',

    plugins: [
      // only throw errors while building if we are not
      // in development or with watch enabled
      ...(watch || action === actions.DEVELOP ? [] : [new NoErrorsPlugin()]),

      // only include the optimization plugins if
      // the flag is enabled
      ...(optimize ? [
        new webpack.optimize.DedupePlugin(),
        new webpack.optimize.UglifyJsPlugin({
          sourceMap: true
        }),

        // signal loaders to minimize
        // https://webpack.js.org/guides/migrating/#uglifyjsplugin-minimize-loaders
        new webpack.LoaderOptionsPlugin({
          minimize: true
        })<commit_msg>Update NoErrorsPlugin to its Webpack 2 name 🤷‍♂️<commit_after>import CleanWebpackPlugin from 'clean-webpack-plugin'
import merge from 'webpack-merge'
import path from 'path'
import webpack, { DefinePlugin, HotModuleReplacementPlugin, NoEmitOnErrorsPlugin } from 'webpack'
import WebpackMd5Hash from 'webpack-md5-hash'

import actions from '../actions'
import fileExtensions from '../file-extensions'

import buildLibraryConfig from './build-library-config'
import buildPagesConfig from './build-pages-config'
import buildLoadersConfig from './loaders'

/**
 * Takes a saguiConfig object and construct a webpack configuration object
 * It support two different types of archetypes; pages and libraries
 *
 * @return ready to use webpack configuration as an array
 */
export default (saguiConfig = {}) => {
  const { pages = [], libraries = [], ...sharedSaguiConfig } = saguiConfig

  const sharedWebpackConfig = merge.smart(
    buildSharedWebpackConfig(sharedSaguiConfig),
    buildLoadersConfig(sharedSaguiConfig),
    sharedSaguiConfig.webpack
  )

  return [
    ...(pages.length > 0 ? [buildPagesConfig(pages, sharedSaguiConfig)] : []),
    ...libraries.map((libraryConfig) => buildLibraryConfig(libraryConfig, sharedSaguiConfig))
  ].map((entryPointWebpackConfig) => merge.smart(
    sharedWebpackConfig,
    entryPointWebpackConfig
  ))
}

const buildSharedWebpackConfig = (saguiConfig) => {
  const { action, projectPath, saguiPath, watch, optimize } = saguiConfig

  const projectSourcePath = path.join(projectPath, 'src')

  return {
    context: projectSourcePath,

    devtool: action === actions.BUILD ? 'source-map' : 'inline-source-map',

    plugins: [
      // only throw errors while building if we are not
      // in development or with watch enabled
      ...(watch || action === actions.DEVELOP ? [] : [new NoEmitOnErrorsPlugin()]),

      // only include the optimization plugins if
      // the flag is enabled
      ...(optimize ? [
        new webpack.optimize.DedupePlugin(),
        new webpack.optimize.UglifyJsPlugin({
          sourceMap: true
        }),

        // signal loaders to minimize
        // https://webpack.js.org/guides/migrating/#uglifyjsplugin-minimize-loaders
        new webpack.LoaderOptionsPlugin({
          minimize: true
        })
{'fraction_non_alphanumeric': 0.10961325966850828, 'fraction_numerical': 0.0015469613259668509, 'mean_word_length': 3.608961303462322, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 2, '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': '753204', 'n_tokens_mistral': 1272, 'n_tokens_neox': 1257, 'n_words': 341}