{"library":"prebuild-webpack-plugin","title":"Prebuild Webpack Plugin","description":"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.","language":"javascript","status":"active","last_verified":"Tue Apr 21","install":{"commands":["npm install prebuild-webpack-plugin"],"cli":null},"imports":["import PrebuildPlugin from 'prebuild-webpack-plugin';","const PrebuildPlugin = require('prebuild-webpack-plugin');"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"const PrebuildPlugin = require('prebuild-webpack-plugin');\nconst path = require('path');\nconst fs = require('fs/promises');\n\nmodule.exports = {\n  // ... webpack config ...\n  plugins: [\n    new PrebuildPlugin({\n      build: async (compiler, compilation, matchedFiles) => {\n        console.log('Prebuild phase started!');\n        // Example: Read and log content of matched markdown files\n        for (const file of matchedFiles) {\n          const content = await fs.readFile(file, 'utf8');\n          console.log(`Prebuilt content of ${path.basename(file)}:\\n${content.substring(0, 100)}...`);\n        }\n        console.log('Prebuild phase completed!');\n      },\n      watch: async (compiler, compilation, changedFile) => {\n        console.log(`File changed in watch mode: ${changedFile}`);\n        // Example: Process the changed file on each rebuild\n        if (changedFile.endsWith('.md')) {\n          const content = await fs.readFile(changedFile, 'utf8');\n          console.log(`Watch-mode processing for ${path.basename(changedFile)}:\\n${content.substring(0, 50)}...`);\n        }\n      },\n      files: { \n        pattern: '**/*.md', \n        options: { cwd: path.resolve(__dirname, 'src') }, \n        addFilesAsDependencies: true \n      },\n      clearCacheOnUpdate: false\n    }),\n  ],\n};","lang":"javascript","description":"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}