<commit_before>const webpack = require('webpack');
const path = require('path');
const fs = require('fs');
const glob = require('glob');
const ManifestPlugin = require('webpack-manifest-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const Dotenv = require('dotenv');
const config = require('./assets.config');
const WebpackCleanupPlugin = require('webpack-cleanup-plugin');

// Load .env settings
const parsedEnv = (function loadDotEnvFile() {
  const fileString = fs.readFileSync(`${config.appPath}/.env`, { encoding: 'utf-8' });
  // Ensure that it works with `export` suffix on variables
  const parsedObj = Dotenv.parse(fileString.replace(/export\s+/g, ''));

  return Object.entries(parsedObj)
    .map(([k, v]) => [`process.env.${k}`, JSON.stringify(v)])
    // eslint-disable-next-line no-param-reassign
    .reduce((obj, [k, v]) => { obj[k] = v; return obj; }, {})
  ;
}());

if (!process.env.NODE_ENV) {
  console.error('NODE_ENV variable is not set!'); // eslint-disable-line no-console
  process.exit(1);
}

const extractCssLoader = ExtractTextPlugin.extract({
  use: {
    loader: 'css-loader',
    options: {
      sourceMap: true,
    },
  },
});

const extractSassLoader = ExtractTextPlugin.extract({
  use: [
    {
      loader: 'css-loader',
      options: {
        sourceMap: true,
      },
    },
    {
      loader: 'sass-loader',
      options: {
        sourceMap: true,
      },
    },
  ],
});

let plugins = [
  // Do not allow files with errors to continue the compilation
  new webpack.NoEmitOnErrorsPlugin(),

  // Remove old files between compilations
  new WebpackCleanupPlugin({
    quiet: true,
  }),

  // Extract CSS
  new ExtractTextPlugin({
    filename: '[name]-[sha256:contenthash:hex:64].css',
    allChunks: true,
  }),

  // Create a manifest.json file
  new ManifestPlugin({
    fileName: 'manifest.json',
  }),

  // Resolve libraries at compile time for components that depends on libraries
  // that are not explicitely set as a dependency. Most likely, it will be for
  // those libraries that expect jQuery or some other plugin to be required in
  // the browser before it gets loaded.
  new webpack.ProvidePlugin({
    $: 'jquery',
    jQuery: 'jquery',
    Tether: 'tether',
    'window.jQuery': 'jquery',
    'window.Tether': 'tether',
  }),

  // Set NODE_ENV to every module
  new webpack.DefinePlugin(Object.assign(parsedEnv, {
    'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
  })),

  // Keep legacy support to plugins built for Webpack 1
  new webpack.LoaderOptionsPlugin({
    options: {
      context: config.appPath,
    },
  }),
];

try {
  // Adds environment-specific plugins
  fs.statSync(`${config.appPath}/config/webpack.${process.env.NODE_ENV}.plugins.js`).isFile();
  // eslint-disable-next-line global-require, import/no-dynamic-require
  plugins = plugins.concat(require(`${config.appPath}/config/webpack.${process.env.NODE_ENV}.plugins.js`));
} catch (e) {} // eslint-disable-line no-empty

// Optimize the generation of SourceMaps
// More info: https://webpack.github.io/docs/build-performance.html
let devtool;
if (process.env.NODE_ENV === 'production') {
  devtool = 'source-map';
} else if (process.env.NODE_ENV === 'test') {
  devtool = 'inline-source-map';<commit_msg>Remove ProvidePlugin<commit_after>const webpack = require('webpack');
const path = require('path');
const fs = require('fs');
const glob = require('glob');
const ManifestPlugin = require('webpack-manifest-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const Dotenv = require('dotenv');
const config = require('./assets.config');
const WebpackCleanupPlugin = require('webpack-cleanup-plugin');

// Load .env settings
const parsedEnv = (function loadDotEnvFile() {
  const fileString = fs.readFileSync(`${config.appPath}/.env`, { encoding: 'utf-8' });
  // Ensure that it works with `export` suffix on variables
  const parsedObj = Dotenv.parse(fileString.replace(/export\s+/g, ''));

  return Object.entries(parsedObj)
    .map(([k, v]) => [`process.env.${k}`, JSON.stringify(v)])
    // eslint-disable-next-line no-param-reassign
    .reduce((obj, [k, v]) => { obj[k] = v; return obj; }, {})
  ;
}());

if (!process.env.NODE_ENV) {
  console.error('NODE_ENV variable is not set!'); // eslint-disable-line no-console
  process.exit(1);
}

const extractCssLoader = ExtractTextPlugin.extract({
  use: {
    loader: 'css-loader',
    options: {
      sourceMap: true,
    },
  },
});

const extractSassLoader = ExtractTextPlugin.extract({
  use: [
    {
      loader: 'css-loader',
      options: {
        sourceMap: true,
      },
    },
    {
      loader: 'sass-loader',
      options: {
        sourceMap: true,
      },
    },
  ],
});

let plugins = [
  // Do not allow files with errors to continue the compilation
  new webpack.NoEmitOnErrorsPlugin(),

  // Remove old files between compilations
  new WebpackCleanupPlugin({
    quiet: true,
  }),

  // Extract CSS
  new ExtractTextPlugin({
    filename: '[name]-[sha256:contenthash:hex:64].css',
    allChunks: true,
  }),

  // Create a manifest.json file
  new ManifestPlugin({
    fileName: 'manifest.json',
  }),

  // Set NODE_ENV to every module
  new webpack.DefinePlugin(Object.assign(parsedEnv, {
    'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
  })),

  // Keep legacy support to plugins built for Webpack 1
  new webpack.LoaderOptionsPlugin({
    options: {
      context: config.appPath,
    },
  }),
];

try {
  // Adds environment-specific plugins
  fs.statSync(`${config.appPath}/config/webpack.${process.env.NODE_ENV}.plugins.js`).isFile();
  // eslint-disable-next-line global-require, import/no-dynamic-require
  plugins = plugins.concat(require(`${config.appPath}/config/webpack.${process.env.NODE_ENV}.plugins.js`));
} catch (e) {} // eslint-disable-line no-empty

// Optimize the generation of SourceMaps
// More info: https://webpack.github.io/docs/build-performance.html
let devtool;
if (process.env.NODE_ENV === 'production') {
  devtool = 'source-map';
} else if (process.env.NODE_ENV === 'test') {
  devtool = 'inline-source-map';
{'fraction_non_alphanumeric': 0.15899853682328077, 'fraction_numerical': 0.002601203056413591, 'mean_word_length': 3.546932742054693, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '2452771', 'n_tokens_mistral': 1972, 'n_tokens_neox': 1935, 'n_words': 447}