{"id":16500,"library":"pre-build-webpack","title":"Webpack Pre-Build Hook Plugin","description":"The `pre-build-webpack` package provides a Webpack plugin that allows developers to execute a custom callback function immediately before the Webpack build process commences. Currently at version 0.1.0, the package appears to be an early-stage project that has seen no updates in several years, suggesting it is no longer actively maintained. Its core functionality is to offer a simple hook for pre-build tasks, such as cleaning directories, preparing environment variables, or dynamically adjusting configuration, prior to any asset compilation. This differentiates it from post-build plugins like `on-build-webpack` by targeting an earlier stage in the compilation lifecycle. Given its age and low version number, users should be cautious about its compatibility with modern Webpack versions (v4, v5, or v6+) and the availability of similar or native functionality within Webpack itself.","status":"abandoned","version":"0.1.0","language":"javascript","source_language":"en","source_url":"https://github.com/benelliott/pre-build-webpack","tags":["javascript","webpack"],"install":[{"cmd":"npm install pre-build-webpack","lang":"bash","label":"npm"},{"cmd":"yarn add pre-build-webpack","lang":"bash","label":"yarn"},{"cmd":"pnpm add pre-build-webpack","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"This is a Webpack plugin and requires a Webpack installation to function. The plugin was developed for older Webpack versions, likely v1 or v2.","package":"webpack","optional":false}],"imports":[{"note":"This package was developed in the CommonJS era. Attempting to use ESM import syntax will likely result in a runtime error.","wrong":"import { WebpackPreBuildPlugin } from 'pre-build-webpack';","symbol":"WebpackPreBuildPlugin","correct":"const WebpackPreBuildPlugin = require('pre-build-webpack');"}],"quickstart":{"code":"const path = require('path');\nconst WebpackPreBuildPlugin = require('pre-build-webpack');\n\nmodule.exports = {\n  mode: 'development',\n  entry: './src/index.js',\n  output: {\n    filename: 'bundle.js',\n    path: path.resolve(__dirname, 'dist'),\n  },\n  plugins: [\n    new WebpackPreBuildPlugin(function(compiler) {\n      // This callback runs BEFORE the Webpack build starts.\n      // 'compiler' is typically the Webpack Compiler instance.\n      // The README example shows 'stats', but 'stats' is usually available\n      // AFTER the build. It's recommended to log and inspect the argument\n      // passed to understand its structure in your specific Webpack version.\n      console.log('--- Pre-build Webpack Plugin Fired ---');\n      console.log('Preparing build...');\n      // Example: Cleanup a directory before build\n      // const fs = require('fs');\n      // const distPath = path.resolve(__dirname, 'dist');\n      // if (fs.existsSync(distPath)) {\n      //   fs.rmdirSync(distPath, { recursive: true });\n      //   console.log('Cleaned ' + distPath);\n      // }\n      console.log('--- Pre-build tasks completed ---');\n    }),\n  ],\n};\n","lang":"javascript","description":"This quickstart demonstrates how to integrate `WebpackPreBuildPlugin` into a `webpack.config.js` file, showcasing a basic pre-build logging operation."},"warnings":[{"fix":"Consider using native Webpack hooks (e.g., `compiler.hooks.beforeRun.tap` or `compiler.hooks.beforeCompile.tap`) or a more modern plugin for pre-build operations, as this plugin is deprecated by core Webpack functionality.","message":"This plugin was released 8 years ago and is designed for older versions of Webpack (likely v1-v3). It is highly unlikely to be compatible with Webpack v4, v5, or v6+ without significant issues or modification.","severity":"breaking","affected_versions":"<=0.1.0"},{"fix":"Always log the argument passed to the callback function (e.g., `console.log(arguments[0]);`) to verify what data is actually available at the pre-build stage for your specific Webpack version.","message":"The documentation example shows `new WebpackPreBuildPlugin(function(stats) { ... })`. However, the `stats` object is typically generated *after* the build completes. At a 'pre-build' stage, the `compiler` instance or other pre-compilation data is usually passed. The actual argument passed to the callback might differ, or `stats` might be `undefined` or incomplete.","severity":"gotcha","affected_versions":"<=0.1.0"},{"fix":"Ensure you are using `require('pre-build-webpack')` in a CommonJS file or configure your build system to correctly handle CJS modules within an ESM project, though this is generally not recommended for abandoned packages.","message":"The package is explicitly CommonJS (`require`). Attempting to `import` it in an ES Module context will result in a `TypeError: require is not a function` or similar module resolution errors.","severity":"gotcha","affected_versions":"<=0.1.0"},{"fix":"Migrate to using native Webpack hooks. For example:\n```javascript\n// In webpack.config.js\nmodule.exports = {\n  // ...\n  plugins: [\n    {\n      apply: (compiler) => {\n        compiler.hooks.beforeRun.tap('MyPreBuildPlugin', (compiler) => {\n          console.log('Native pre-build hook fired!');\n          // Your pre-build logic here\n        });\n      },\n    },\n  ],\n};\n```","message":"This package is effectively abandoned, with no updates in 8 years. It uses an older Webpack plugin API. Modern Webpack versions provide more robust and well-documented ways to hook into the build lifecycle, such as `compiler.hooks.beforeRun` or `compiler.hooks.beforeCompile`.","severity":"deprecated","affected_versions":"<=0.1.0"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"Ensure you are using `const WebpackPreBuildPlugin = require('pre-build-webpack');` and that Webpack is installed in your project. Verify the Webpack version you are using is compatible with such an old plugin (likely Webpack v1-v3).","cause":"The `WebpackPreBuildPlugin` might be incorrectly imported or the module itself is not returning a class or constructor in the expected way, especially if the `require` statement is incorrect or an old webpack version is used.","error":"TypeError: WebpackPreBuildPlugin is not a constructor"},{"fix":"Run `npm install --save-dev pre-build-webpack` to ensure the package is installed and available in your `node_modules` directory.","cause":"The package `pre-build-webpack` is not installed or Webpack cannot resolve its path.","error":"ERROR in   Error: Cannot find module 'pre-build-webpack'"}],"ecosystem":"npm"}