<commit_before>const webpack = require('webpack');
const StaticSiteGeneratorPlugin = require('static-site-generator-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const nodeExternals = require('webpack-node-externals');
const builds = require('../builds');
const lodash = require('lodash');
const flatten = require('lodash/flatten');
const args = require('../args');
const bundleAnalyzerPlugin = require('./plugins/bundleAnalyzer');
const utils = require('./utils');
const debug = require('debug')('sku:webpack');

const webpackMode = utils.isProductionBuild ? 'production' : 'development';

const buildWebpackConfigs = builds.map(
  ({ name, paths, env, locales, webpackDecorator, port, polyfills }) => {
    const envVars = lodash
      .chain(env)
      .mapValues((value, key) => {
        if (typeof value !== 'object') {
          return JSON.stringify(value);
        }

        const valueForEnv = value[args.env];

        if (typeof valueForEnv === 'undefined') {
          console.log(
            `WARNING: Environment variable "${key}" for build "${name}" is missing a value for the "${
              args.env
            }" environment`
          );
          process.exit(1);
        }

        return JSON.stringify(valueForEnv);
      })
      .set('SKU_ENV', JSON.stringify(args.env))
      .set('PORT', JSON.stringify(port))
      .mapKeys((value, key) => `process.env.${key}`)
      .value();

    const resolvedPolyfills = polyfills.map(polyfill => {
      return require.resolve(polyfill, { paths: [process.cwd()] });
    });

    const devServerEntries = [
      `${require.resolve(
        'webpack-dev-server/client'
      )}?http://localhost:${port}/`
    ];

    const entry =
      args.script === 'start'
        ? [...resolvedPolyfills, ...devServerEntries, paths.clientEntry]
        : [...resolvedPolyfills, paths.clientEntry];

    const internalJs = [
      ...paths.src,
      ...paths.compilePackages.map(utils.resolvePackage)
    ];

    debug({ build: name || 'default', internalJs });

    const publicPath = args.script === 'start' ? '/' : paths.publicPath;

    const result = [
      {
        name: 'client',
        mode: webpackMode,
        entry,
        output: {
          path: paths.dist,
          publicPath,
          filename: '[name].js'
        },
        optimization: {
          nodeEnv: process.env.NODE_ENV,
          minimize: utils.isProductionBuild,
          concatenateModules: utils.isProductionBuild
        },
        module: {
          rules: [
            {
              test: /(?!\.css)\.js$/,
              include: internalJs,
              use: utils.makeJsLoaders({ target: 'browser' })
            },
            {
              test: /(?!\.css)\.js$/,
              exclude: internalJs,
              use: [
                {
                  loader: require.resolve('babel-loader'),
                  options: {
                    babelrc: false,
                    presets: [require.resolve('babel-preset-env')]
                  }
                }
              ]
            },
            {
              test: /\.css\.js$/,
              use: [MiniCssExtractPlugin.loader].concat(
                utils.makeCssLoaders({ js: true })
              )
            },
            {
              test: /\.mjs$/,
              include: /node_modules/,
              type: 'javascript/auto'
            },
            {
              test: /\.less$/,
              oneOf: [
                ...paths.compilePackages.map(packageName => ({
                  include: utils.resolvePackage(packageName),
                  use: [MiniCssExtractPlugin.loader].concat(
                    utils.makeCssLoaders({ packageName })
                  )
                })),
                {
                  exclude: /node_modules/,<commit_msg>fix(webpack): Dont compile external modules to commonjs (#155)<commit_after>const webpack = require('webpack');
const StaticSiteGeneratorPlugin = require('static-site-generator-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const nodeExternals = require('webpack-node-externals');
const builds = require('../builds');
const lodash = require('lodash');
const flatten = require('lodash/flatten');
const args = require('../args');
const bundleAnalyzerPlugin = require('./plugins/bundleAnalyzer');
const utils = require('./utils');
const debug = require('debug')('sku:webpack');

const webpackMode = utils.isProductionBuild ? 'production' : 'development';

const buildWebpackConfigs = builds.map(
  ({ name, paths, env, locales, webpackDecorator, port, polyfills }) => {
    const envVars = lodash
      .chain(env)
      .mapValues((value, key) => {
        if (typeof value !== 'object') {
          return JSON.stringify(value);
        }

        const valueForEnv = value[args.env];

        if (typeof valueForEnv === 'undefined') {
          console.log(
            `WARNING: Environment variable "${key}" for build "${name}" is missing a value for the "${
              args.env
            }" environment`
          );
          process.exit(1);
        }

        return JSON.stringify(valueForEnv);
      })
      .set('SKU_ENV', JSON.stringify(args.env))
      .set('PORT', JSON.stringify(port))
      .mapKeys((value, key) => `process.env.${key}`)
      .value();

    const resolvedPolyfills = polyfills.map(polyfill => {
      return require.resolve(polyfill, { paths: [process.cwd()] });
    });

    const devServerEntries = [
      `${require.resolve(
        'webpack-dev-server/client'
      )}?http://localhost:${port}/`
    ];

    const entry =
      args.script === 'start'
        ? [...resolvedPolyfills, ...devServerEntries, paths.clientEntry]
        : [...resolvedPolyfills, paths.clientEntry];

    const internalJs = [
      ...paths.src,
      ...paths.compilePackages.map(utils.resolvePackage)
    ];

    debug({ build: name || 'default', internalJs });

    const publicPath = args.script === 'start' ? '/' : paths.publicPath;

    const result = [
      {
        name: 'client',
        mode: webpackMode,
        entry,
        output: {
          path: paths.dist,
          publicPath,
          filename: '[name].js'
        },
        optimization: {
          nodeEnv: process.env.NODE_ENV,
          minimize: utils.isProductionBuild,
          concatenateModules: utils.isProductionBuild
        },
        module: {
          rules: [
            {
              test: /(?!\.css)\.js$/,
              include: internalJs,
              use: utils.makeJsLoaders({ target: 'browser' })
            },
            {
              test: /(?!\.css)\.js$/,
              exclude: internalJs,
              use: [
                {
                  loader: require.resolve('babel-loader'),
                  options: {
                    babelrc: false,
                    presets: [
                      [require.resolve('babel-preset-env'), { modules: false }]
                    ]
                  }
                }
              ]
            },
            {
              test: /\.css\.js$/,
              use: [MiniCssExtractPlugin.loader].concat(
                utils.makeCssLoaders({ js: true })
              )
            },
            {
              test: /\.mjs$/,
              include: /node_modules/,
              type: 'javascript/auto'
            },
            {
              test: /\.less$/,
              oneOf: [
                ...paths.compilePackages.map(packageName => ({
                  include: utils.resolvePackage(packageName),
                  use: [MiniCssExtractPlugin.loader].concat(
                    utils.makeCssLoaders({ packageName })
                  )
                })),
                {
                  exclude: /node_modules/,
{'fraction_non_alphanumeric': 0.14250991428936932, 'fraction_numerical': 0.0006396315722144045, 'mean_word_length': 1.6591836734693877, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '646255', 'n_tokens_mistral': 2165, 'n_tokens_neox': 2090, 'n_words': 400}