{"id":12883,"library":"before-build-webpack","title":"Webpack Before Build Plugin","description":"The `before-build-webpack` plugin provides a mechanism to execute custom logic before, after, or during specific compilation lifecycle events within Webpack. It supports Webpack versions 1 through 5, offering flexibility for projects with varying Webpack installations. The current stable version is `0.2.15`, and the package appears to be in a maintenance mode with infrequent updates, though it remains compatible with recent Webpack versions. Its key differentiator is the ability to halt compilation conditionally by not invoking the provided callback, making it suitable for pre-build checks, environment validation, or complex conditional builds. This plugin acts as a wrapper around Webpack's compiler hooks, abstracting away some version-specific differences in hook names.","status":"maintenance","version":"0.2.15","language":"javascript","source_language":"en","source_url":"https://github.com/artemdudkin/before-build-webpack","tags":["javascript","webpack","conditional","before build","pre build"],"install":[{"cmd":"npm install before-build-webpack","lang":"bash","label":"npm"},{"cmd":"yarn add before-build-webpack","lang":"bash","label":"yarn"},{"cmd":"pnpm add before-build-webpack","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"This package is a Webpack plugin and requires Webpack to be installed in the project to function.","package":"webpack","optional":false}],"imports":[{"note":"While the README shows CommonJS `require`, modern Node.js environments often use ESM. This package likely exports a default in ESM contexts, but primarily expects CommonJS `require` for configuration files.","wrong":"const WebpackBeforeBuildPlugin = require('before-build-webpack').default;","symbol":"WebpackBeforeBuildPlugin","correct":"import WebpackBeforeBuildPlugin from 'before-build-webpack';"},{"note":"The canonical CommonJS import method as shown in the package's documentation, suitable for `webpack.config.js` files.","wrong":"import { WebpackBeforeBuildPlugin } from 'before-build-webpack';","symbol":"WebpackBeforeBuildPlugin (CommonJS)","correct":"const WebpackBeforeBuildPlugin = require('before-build-webpack');"}],"quickstart":{"code":"const path = require('path');\nconst WebpackBeforeBuildPlugin = require('before-build-webpack');\n\nmodule.exports = {\n  mode: 'development',\n  entry: './src/index.js',\n  output: {\n    path: path.resolve(__dirname, 'dist'),\n    filename: 'bundle.js',\n  },\n  plugins: [\n    new WebpackBeforeBuildPlugin(function(stats, callback) {\n      console.log('Webpack build is about to start...');\n      // Example: Check for an environment variable\n      if (process.env.SKIP_BUILD === 'true') {\n        console.warn('Skipping compilation due to SKIP_BUILD environment variable.');\n        // DO NOT call callback() to stop compilation\n      } else {\n        console.log('Proceeding with compilation.');\n        callback(); // IMPORTANT: Call callback() to proceed with compilation\n      }\n    }, ['run', 'watch-run'])\n  ]\n};","lang":"javascript","description":"This quickstart demonstrates how to integrate `before-build-webpack` into a Webpack configuration to execute custom logic before compilation, with an example of conditionally halting the build based on an environment variable."},"warnings":[{"fix":"Always ensure `callback()` is invoked when you want the compilation to proceed. Only omit it if you explicitly intend to stop the build.","message":"Failing to call the `callback()` function provided to the plugin's handler will stop the Webpack compilation indefinitely without an error message, leading to a hanging process.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Refer to the official Webpack documentation for your version's compiler hook names. The plugin generally accepts both dashed and camelCase versions but consistency is key.","message":"Webpack's compiler hooks changed naming conventions between v3 (pre-v4) and v4+ (e.g., `watch-run` became `watchRun`). While the plugin claims to support both, ensure you use the correct hook names for your specific Webpack version to avoid the plugin not firing.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"For new projects or complex scenarios, consider exploring direct Webpack compiler hooks or more actively maintained plugins if this package doesn't meet future requirements.","message":"The `before-build-webpack` package has not seen significant updates recently (last commit March 2023) and is on a `0.x.x` version number, suggesting it's in maintenance mode. While it supports Webpack v5, newer Webpack versions might introduce more direct or performant ways to achieve similar functionality.","severity":"deprecated","affected_versions":"<1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Ensure `callback()` is called at the end of your plugin's handler function, unless you deliberately want to stop the build.","cause":"The `callback()` function provided by the plugin was not invoked within your custom logic, preventing Webpack from proceeding.","error":"Webpack compilation hangs or never finishes after 'before-build-webpack' plugin logs."},{"fix":"Verify the hook names against your Webpack version's documentation (e.g., `watchRun` for Webpack 4+ versus `watch-run` for older versions) and ensure the event is relevant to your build type (e.g., `watch-run` for `webpack --watch`).","cause":"Incorrect Webpack hook names were provided to the plugin, or the event itself is not being triggered in the current Webpack context (e.g., 'run' vs 'watch-run').","error":"Plugin callback never fires for expected Webpack event."}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":""}