A webpack plugin that replaces strings in files after the compilation is done. Version 1.0.6 (latest) provides a simple API to define replacement rules for files in specified directories, supporting both string and regex patterns with string or function replacements. It is useful for modifying output files (HTML, CSS, JS) that are not processed by loaders. Compared to alternatives like string-replace-webpack-plugin, it offers a cleaner configuration with an array of rule sets and supports multiple file matching via `files` or `test` patterns.
npm install replace-in-file-webpack-pluginVerified import paths — ran on the pinned version, not inferred.
Shows how to configure the plugin in webpack.config.js to replace placeholders in output files.
Ensure replace functions always return a string.
Provide either `files` (array of filenames) or `test` (regex or array of regexes) in each config object.
Use `test` with regex if you need pattern matching, or list all filenames explicitly.
Use `const ReplaceInFileWebpackPlugin = require('replace-in-file-webpack-plugin');` or `import ReplaceInFileWebpackPlugin from 'replace-in-file-webpack-plugin';`Run `npm install replace-in-file-webpack-plugin --save-dev`
Wrap your config in an array: `new ReplaceInFileWebpackPlugin([{ ... }])`