Registry / devops / before-build-webpack

before-build-webpack

JSON →
library0.2.15jsnpmunverified

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.

npm install before-build-webpack
INSTALL
IMPORT
SIG · BEFORE-BUILD-WEBPA
B
before-build-webpack
devopsjavascriptv0.2.15
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

WebpackBeforeBuildPlugin
import WebpackBeforeBuildPlugin from 'before-build-webpack';
const WebpackBeforeBuildPlugin = require('before-build-webpack').default;
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.
WebpackBeforeBuildPlugin (CommonJS)
const WebpackBeforeBuildPlugin = require('before-build-webpack');
import { WebpackBeforeBuildPlugin } from 'before-build-webpack';
The canonical CommonJS import method as shown in the package's documentation, suitable for `webpack.config.js` files.

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.

const path = require('path'); const WebpackBeforeBuildPlugin = require('before-build-webpack'); module.exports = { mode: 'development', entry: './src/index.js', output: { path: path.resolve(__dirname, 'dist'), filename: 'bundle.js', }, plugins: [ new WebpackBeforeBuildPlugin(function(stats, callback) { console.log('Webpack build is about to start...'); // Example: Check for an environment variable if (process.env.SKIP_BUILD === 'true') { console.warn('Skipping compilation due to SKIP_BUILD environment variable.'); // DO NOT call callback() to stop compilation } else { console.log('Proceeding with compilation.'); callback(); // IMPORTANT: Call callback() to proceed with compilation } }, ['run', 'watch-run']) ] };
Debug
Known issues
gotchaFailing 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.
fix
Always ensure `callback()` is invoked when you want the compilation to proceed. Only omit it if you explicitly intend to stop the build.
affects: >=0.1.0
gotchaWebpack'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.
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.
affects: >=0.1.0
deprecatedThe `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.
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.
affects: <1.0.0
Errors
Common errors & fixes
Webpack compilation hangs or never finishes after 'before-build-webpack' plugin logs.
The `callback()` function provided by the plugin was not invoked within your custom logic, preventing Webpack from proceeding.
fix
Ensure `callback()` is called at the end of your plugin's handler function, unless you deliberately want to stop the build.
Plugin callback never fires for expected Webpack event.
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').
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`).
Upgrade
Version history
0.2.15latest on npm
Audit
Dependencies
webpackrequiredThis package is a Webpack plugin and requires Webpack to be installed in the project to function.
Agent activity
4 hits · last 30 days
node
4
Resources
before-build-webpack — npm install before-build-webpack · libregistry