Prebuild Webpack Plugin is a utility designed to execute file processing and I/O operations before a webpack build commences. It currently stands at stable version 1.1.1, with a history of steady, active development and releases addressing issues and improving performance. This plugin distinguishes itself by offering dedicated `build` and `watch` hooks that fire before the initial webpack compilation and on subsequent rebuilds, respectively. It supports file matching via minimatch patterns, allowing for targeted pre-processing. A key feature is the ability to explicitly add matched files to webpack's dependency tree and specific handling for complex build environments like Next.js through the `compilationNameFilter` option, enabling users to optimize for client-side or server-side compilations. It is particularly useful for scenarios requiring data transformation or external resource fetching prior to bundling, providing a flexible interface for such tasks.
npm install prebuild-webpack-pluginVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to integrate `PrebuildPlugin` into a webpack configuration. It sets up `build` and `watch` hooks to process markdown files in the `src` directory before the initial build and upon subsequent changes, logging their content. It also configures file matching and adds matched files as webpack dependencies.
Update your `package.json` dependencies and `import`/`require` statements to use the new package name: `prebuild-webpack-plugin`.
Change your import statement from `import { PrebuildWebpackPlugin } from '...'` to `import PrebuildPlugin from '...'` for ESM, or `const PrebuildPlugin = require('...')` for CommonJS.Upgrade to v1.1.0 or later. If you need to explicitly replicate the old behavior (i.e., resolve the original path of a symlink), pass `realpath: true` to `files.options`.
Use `clearCacheOnUpdate: true` only when strictly necessary for dynamic file additions in development. For static file sets or less frequent additions, it's more performant to restart the build process.
Use the `compilationNameFilter` option to specify which webpack compilation should execute the plugin's logic. For Next.js, you might pass `'client'` to run only for the client-side build.
Update your import statement to `import PrebuildPlugin from 'prebuild-webpack-plugin';` for ESM or `const PrebuildPlugin = require('prebuild-webpack-plugin');` for CommonJS.Update your `package.json` to use `prebuild-webpack-plugin` and ensure all import/require statements also use the new package name.
For development workflows where new files are frequently added, set `clearCacheOnUpdate: true` in the plugin options. Be aware of the potential performance impact. For production builds or less dynamic scenarios, restart the webpack process after adding new files.