{"library":"replace-in-file-webpack-plugin","title":"ReplaceInFileWebpackPlugin","description":"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.","language":"javascript","status":"active","last_verified":"Sat Apr 25","install":{"commands":["npm install replace-in-file-webpack-plugin"],"cli":null},"imports":["import ReplaceInFileWebpackPlugin from 'replace-in-file-webpack-plugin'","const ReplaceInFileWebpackPlugin = require('replace-in-file-webpack-plugin')"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"// webpack.config.js\nconst path = require('path');\nconst ReplaceInFileWebpackPlugin = require('replace-in-file-webpack-plugin');\n\nmodule.exports = {\n  entry: './src/index.js',\n  output: {\n    path: path.resolve(__dirname, 'dist'),\n    filename: 'bundle.js',\n  },\n  plugins: [\n    new ReplaceInFileWebpackPlugin([\n      {\n        dir: 'dist',\n        files: ['index.html'],\n        rules: [\n          { search: '{{VERSION}}', replace: '1.0.0' },\n          { search: /@year/g, replace: '2024' },\n        ],\n      },\n    ]),\n  ],\n};","lang":"javascript","description":"Shows how to configure the plugin in webpack.config.js to replace placeholders in output files.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}