Webpack Pre-Build Hook Plugin

0.1.0 · abandoned · verified Wed Apr 22

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.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to integrate `WebpackPreBuildPlugin` into a `webpack.config.js` file, showcasing a basic pre-build logging operation.

const path = require('path');
const WebpackPreBuildPlugin = require('pre-build-webpack');

module.exports = {
  mode: 'development',
  entry: './src/index.js',
  output: {
    filename: 'bundle.js',
    path: path.resolve(__dirname, 'dist'),
  },
  plugins: [
    new WebpackPreBuildPlugin(function(compiler) {
      // This callback runs BEFORE the Webpack build starts.
      // 'compiler' is typically the Webpack Compiler instance.
      // The README example shows 'stats', but 'stats' is usually available
      // AFTER the build. It's recommended to log and inspect the argument
      // passed to understand its structure in your specific Webpack version.
      console.log('--- Pre-build Webpack Plugin Fired ---');
      console.log('Preparing build...');
      // Example: Cleanup a directory before build
      // const fs = require('fs');
      // const distPath = path.resolve(__dirname, 'dist');
      // if (fs.existsSync(distPath)) {
      //   fs.rmdirSync(distPath, { recursive: true });
      //   console.log('Cleaned ' + distPath);
      // }
      console.log('--- Pre-build tasks completed ---');
    }),
  ],
};

view raw JSON →