Webpack Config Finder Utility

2.2.1 · maintenance · verified Sun Apr 19

find-webpack is a utility library designed to programmatically locate and modify Webpack configuration settings, particularly useful for projects built with `react-scripts` (Create React App) or custom Webpack setups. As of its latest stable version, 2.2.1 (released January 2021), it provides functions to extract Webpack options, including handling the nuances of `react-scripts`'s hidden configurations. It also offers specific utilities for integrating with tools like Cypress, enabling cleanup of optimization plugins and dynamic addition of folders to Babel's transpilation scope for testing purposes. While its release cadence has been irregular since 2021, it was actively maintained with features and bug fixes throughout 2020, differentiating itself by simplifying complex Webpack config access and modification for specific ecosystem integrations.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to find an application's Webpack configuration (especially from react-scripts) and then modify it using `cleanForCypress` to prepare it for Cypress component testing, including adding coverage instrumentation and specifying additional folders for Babel transpilation.

import { getWebpackOptions, cleanForCypress } from 'find-webpack';
import path from 'path';

const projectRoot = process.cwd();

console.log('Attempting to find Webpack options...');
let webpackConfig = getWebpackOptions();

if (webpackConfig) {
  console.log('Webpack config found. Initial entry points:', webpackConfig.entry);

  // Example of cleaning the config for Cypress with coverage and custom folder transpilation
  const cypressComponentFolder = path.join(projectRoot, 'cypress', 'component');
  const cypressFixturesFolder = path.join(projectRoot, 'cypress', 'fixtures');

  const cleanOptions = {
    reactScripts: true, // Specific cleanup for react-scripts projects
    coverage: true,     // Add istanbul babel plugin for code coverage
    addFolderToTranspile: [cypressComponentFolder, cypressFixturesFolder],
    looseModules: true // Enable @babel/plugin-transform-modules-commonjs
  };

  cleanForCypress(cleanOptions, webpackConfig);
  console.log('Webpack config cleaned for Cypress. Modified entry points:', webpackConfig.entry);
  // console.log('Full modified config:', JSON.stringify(webpackConfig, null, 2));
} else {
  console.warn('Could not find Webpack options. Ensure package.json is in CWD or pass a config path.');
}

view raw JSON →