<commit_before>/**
 * COMMON WEBPACK CONFIGURATION
 */
const path              = require('path');
const webpack           = require('webpack');
const _                 = require('lodash');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const TransferPlugin    = require('transfer-webpack-plugin');
const AssetsManifest    = require('webpack-assets-manifest');
const autoprefixer      = require('autoprefixer');
const FaviconsPlugin    = require('favicons-webpack-plugin');
const BundleAnyzPlugin  = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const genPugFiles       = require('./tasks/generate-pug-files.js');
const OfflinePlugin     = require('offline-plugin');
const CTR               = require('ctr').stylus;
const {getConfig, env}  = require('./../helpers.js');
const enviroment        = env.get();
const ctr               = new CTR();


const configBase = function (options = {}) {
  const production = enviroment === 'production';
  //config the base context
  const baseContextDir = getConfig('webpack.base.context') || 'src';
  const baseContext = path.join(process.cwd(), baseContextDir);
  //css extract file name
  let cssExtract = getConfig('webpack.base.plugins.ExtractTextPlugin.filename') || '[name].css';
  cssExtract = _.isFunction(cssExtract) ? cssExtract(env) : cssExtract;

  //gets/sets base configuration
  const baseConfig = _.defaultsDeep(options, {
    context: baseContext
  }, _.omit(getConfig('webpack.base'), 'plugins') || {}, {
    entry: {
      app: './js/index.js'
    },
    resolve: {
      modules: ['node_modules']
    },
    // Make web variables accessible to webpack, e.g. window
    target: 'web'
  });

  //we lookup here in case addHTML is in setting
  let offlinePlugin = getConfig('webpack.production.plugins.OfflinePlugin') || {};
  // gen pug files
  const manifestPath = path.join(baseConfig.output.path, 'manifest.json');
  const results = genPugFiles({
    context: baseContextDir,
    options: {
      manifestPath,
      manifest: true,
      offlinePlugin
    }
  });
  //update from the return
  const {pugFiles} = results;
  ({offlinePlugin} = results);

  /**
   * Hardwired dev config the rest are preconfiged in the .cruzinrc.yml
   */
  const base = _.defaultsDeep(_.omit(baseConfig, 'plugins'), {
    module: {
      rules: [{
        // Transform all .js files required somewhere with Babel
        test: /\.js$/,
        loader: 'babel-loader',
        exclude: /node_modules/
      }, {
        /**
         * Fonts
         */
        test: /\.(eot|ttf|woff|woff2)$/,
        loader: 'file-loader',
        options: {
          name: production ? '[name]-[sha512:hash:base64:7].[ext]' : '[name].[ext]'
        }
      }, {
        /**
         * For pug mixins and includes which have to use this prefix
         * otherwise they get picked up my HtmlWebpackPlugin and as
         * a result they will not work as expected
         */
        test: /.(\.include|\.mixin|\.component|\.icon)\.pug$/,
        loader: 'pug-loader'
      }, {
        /**
         * Image handler + compresses images
         */
        test: /.*\.(gif|png|jpe?g|svg)$/i,
        use: [{
          loader: 'url-loader',
          options: {
            name: production ? '[name]-[sha512:hash:base64:7].[ext]' : '[name].[ext]',
            limit: 1000
          }
        }, {
          loader: 'image-webpack-loader',
          options: {
            mozjpeg: {
              progressive: true
            },
            gifsicle: {
              interlaced: false
            },
            optipng: {
              optimizationLevel: 4
            },
            pngquant: {
              quality: '75-90',
              speed: 3
            }
          }
        }]
      }, {
        test: /\.json$/,
        loader: 'json-loader'
      }, {
        test: /\.(mp4|webm)$/,
        loader: 'url-loader',
        options: {
          limit: 10000
        }
      }, {
        /**
         * Stylus, autoprefixer + ctr
         */
        test: /\.styl$/,
        use: ExtractTextPlugin.extract({
          fallback: 'style-loader',
          use: [{
            loader: 'css-loader',
            options: {
              importLoaders: 2,
              root: '.',
              name: production ? '[name].[hash].css' : '[name].css'
            }
          }, {
            loader: 'postcss-loader',
            // @important the "last 99 versions" if for testing purposes
            options: { plugins: () => [autoprefixer({ browsers: ['last 4 versions'] })] }
          }, {
            /**
             * @note currently ctr is being pulled in via LoaderOptionsPlugin
             * in the plugins since if ctr is defined her it will log out
             * all kinds of internal stylus garbage. This should be resolved in
             * the near future, although, the mode of action remains the same
             * @type {String}
             */
            loader: 'stylus-loader'
          }]
        })
      }]
    },
    plugins: _.union(baseConfig.plugins || [], pugFiles, [
      /**
       * Tells the stylus-loader we wish to use ctr
       * @type {Object}
       */
      new webpack.LoaderOptionsPlugin({<commit_msg>update(__internals__): minimize CSS on production<commit_after>/**
 * COMMON WEBPACK CONFIGURATION
 */
const path              = require('path');
const webpack           = require('webpack');
const _                 = require('lodash');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const TransferPlugin    = require('transfer-webpack-plugin');
const AssetsManifest    = require('webpack-assets-manifest');
const autoprefixer      = require('autoprefixer');
const FaviconsPlugin    = require('favicons-webpack-plugin');
const BundleAnyzPlugin  = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const genPugFiles       = require('./tasks/generate-pug-files.js');
const OfflinePlugin     = require('offline-plugin');
const CTR               = require('ctr').stylus;
const {getConfig, env}  = require('./../helpers.js');
const enviroment        = env.get();
const ctr               = new CTR();


const configBase = function (options = {}) {
  const production = enviroment === 'production';
  //config the base context
  const baseContextDir = getConfig('webpack.base.context') || 'src';
  const baseContext = path.join(process.cwd(), baseContextDir);
  //css extract file name
  let cssExtract = getConfig('webpack.base.plugins.ExtractTextPlugin.filename') || '[name].css';
  cssExtract = _.isFunction(cssExtract) ? cssExtract(env) : cssExtract;

  //gets/sets base configuration
  const baseConfig = _.defaultsDeep(options, {
    context: baseContext
  }, _.omit(getConfig('webpack.base'), 'plugins') || {}, {
    entry: {
      app: './js/index.js'
    },
    resolve: {
      modules: ['node_modules']
    },
    // Make web variables accessible to webpack, e.g. window
    target: 'web'
  });

  //we lookup here in case addHTML is in setting
  let offlinePlugin = getConfig('webpack.production.plugins.OfflinePlugin') || {};
  // gen pug files
  const manifestPath = path.join(baseConfig.output.path, 'manifest.json');
  const results = genPugFiles({
    context: baseContextDir,
    options: {
      manifestPath,
      manifest: true,
      offlinePlugin
    }
  });
  //update from the return
  const {pugFiles} = results;
  ({offlinePlugin} = results);

  /**
   * Hardwired dev config the rest are preconfiged in the .cruzinrc.yml
   */
  const base = _.defaultsDeep(_.omit(baseConfig, 'plugins'), {
    module: {
      rules: [{
        // Transform all .js files required somewhere with Babel
        test: /\.js$/,
        loader: 'babel-loader',
        exclude: /node_modules/
      }, {
        /**
         * Fonts
         */
        test: /\.(eot|ttf|woff|woff2)$/,
        loader: 'file-loader',
        options: {
          name: production ? '[name]-[sha512:hash:base64:7].[ext]' : '[name].[ext]'
        }
      }, {
        /**
         * For pug mixins and includes which have to use this prefix
         * otherwise they get picked up my HtmlWebpackPlugin and as
         * a result they will not work as expected
         */
        test: /.(\.include|\.mixin|\.component|\.icon)\.pug$/,
        loader: 'pug-loader'
      }, {
        /**
         * Image handler + compresses images
         */
        test: /.*\.(gif|png|jpe?g|svg)$/i,
        use: [{
          loader: 'url-loader',
          options: {
            name: production ? '[name]-[sha512:hash:base64:7].[ext]' : '[name].[ext]',
            limit: 1000
          }
        }, {
          loader: 'image-webpack-loader',
          options: {
            mozjpeg: {
              progressive: true
            },
            gifsicle: {
              interlaced: false
            },
            optipng: {
              optimizationLevel: 4
            },
            pngquant: {
              quality: '75-90',
              speed: 3
            }
          }
        }]
      }, {
        test: /\.json$/,
        loader: 'json-loader'
      }, {
        test: /\.(mp4|webm)$/,
        loader: 'url-loader',
        options: {
          limit: 10000
        }
      }, {
        /**
         * Stylus, autoprefixer + ctr
         */
        test: /\.styl$/,
        use: ExtractTextPlugin.extract({
          fallback: 'style-loader',
          use: [{
            loader: 'css-loader',
            options: {
              importLoaders: 2,
              root: '.',
              name: production ? '[name].[hash].css' : '[name].css',
              minimize: production
            }
          }, {
            loader: 'postcss-loader',
            options: { plugins: () => [autoprefixer({ browsers: ['last 4 versions'] })] }
          }, {
            /**
             * @note currently ctr is being pulled in via LoaderOptionsPlugin
             * in the plugins since if ctr is defined her it will log out
             * all kinds of internal stylus garbage. This should be resolved in
             * the near future, although, the mode of action remains the same
             * @type {String}
             */
            loader: 'stylus-loader'
          }]
        })
      }]
    },
    plugins: _.union(baseConfig.plugins || [], pugFiles, [
      /**
       * Tells the stylus-loader we wish to use ctr
       * @type {Object}
       */
      new webpack.LoaderOptionsPlugin({
{'fraction_non_alphanumeric': 0.13785158874916004, 'fraction_numerical': 0.006143803398291255, 'mean_word_length': 1.8410144532315245, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '2871825', 'n_tokens_mistral': 3032, 'n_tokens_neox': 2938, 'n_words': 722}