Webpack OnBuild Plugin

0.1.0 · abandoned · verified Sun Apr 19

The `on-build-webpack` package provides a Webpack plugin designed to execute a callback function immediately after a build completes. Published as version `0.1.0` in October 2014, this package is considered abandoned and is not actively maintained. Its functionality is extremely basic, offering a single post-build hook, which contrasts sharply with the extensive `compiler.hooks` API introduced in modern Webpack versions (v4+). This plugin uses an outdated Webpack API (`compiler.plugin('done', ...)`) that has been replaced by the Tapable hook system (`compiler.hooks.done.tap(...)`). Consequently, it is incompatible with Webpack v4 and newer. Current best practice is to use Webpack's native plugin system directly via `compiler.hooks.done.tap` within a custom plugin.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to integrate the `WebpackOnBuildPlugin` into a `webpack.config.js` file to execute a callback after a successful or failed build. It shows basic setup for a project with `src/index.js` as the entry point, bundling to `dist/bundle.js`. Note: This plugin is outdated and likely incompatible with modern Webpack versions (v4 and above).

const path = require('path');
const WebpackOnBuildPlugin = require('on-build-webpack');

module.exports = {
  mode: 'development',
  entry: './src/index.js',
  output: {
    filename: 'bundle.js',
    path: path.resolve(__dirname, 'dist'),
  },
  plugins: [
    new WebpackOnBuildPlugin(function(stats) {
      // The 'stats' object contains information about the build.
      // For modern Webpack, 'stats.hasErrors()' and 'stats.hasWarnings()' are useful.
      // For this old plugin, the structure of 'stats' might differ.
      if (stats.hasErrors()) {
        console.error('Webpack build failed with errors!');
        console.error(stats.toString({ colors: true }));
      } else {
        console.log('Webpack build completed successfully!');
      }
    }),
  ],
  // Note: This configuration is for demonstration of the plugin's original usage.
  // It is unlikely to work with modern Webpack (v4+).
  // For modern Webpack, directly use compiler.hooks.done.tap.
};

view raw JSON →