{"id":19413,"library":"content-replace-webpack-plugin","title":"content-replace-webpack-plugin","description":"A Webpack plugin that replaces asset content during the emit phase. Version 1.0.0 (stable, no recent updates). It allows specifying replacement rules per file extension, and can also operate on external files not in the Webpack asset pipeline. Simpler alternative to string-replace-loader or replace-in-file-webpack-plugin, but lacks advanced features like regex or pattern matching. Limited to function-based replacements and chunk filtering.","status":"maintenance","version":"1.0.0","language":"javascript","source_language":"en","source_url":"ssh://git@github.com/ali322/content-replace-webpack-plugin","tags":["javascript"],"install":[{"cmd":"npm install content-replace-webpack-plugin","lang":"bash","label":"npm"},{"cmd":"yarn add content-replace-webpack-plugin","lang":"bash","label":"yarn"},{"cmd":"pnpm add content-replace-webpack-plugin","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"CJS only; no ESM or default export for import.","wrong":"import ContentReplacePlugin from 'content-replace-webpack-plugin';","symbol":"default","correct":"const ContentReplacePlugin = require('content-replace-webpack-plugin');"}],"quickstart":{"code":"// webpack.config.js\nconst ContentReplacePlugin = require('content-replace-webpack-plugin');\nmodule.exports = {\n  entry: './index.js',\n  output: { path: './dist', filename: 'bundle.js' },\n  plugins: [\n    new ContentReplacePlugin({\n      chunks: ['main'],\n      rules: {\n        '.js': content => content.replace('foo', 'bar'),\n        '.css': content => content.replace('old-color', 'new-color')\n      }\n    })\n  ]\n};","lang":"javascript","description":"Shows basic usage: replace 'foo' with 'bar' in JS files and 'old-color' with 'new-color' in CSS files of the 'main' chunk."},"warnings":[{"fix":"Ensure the function returns the modified content string.","message":"Replace function must return a string; returning undefined will produce invalid content.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"List all chunk names explicitly in the 'chunks' option, or omit to process all chunks.","message":"Plugin only operates on emitted assets and external files list. Dynamic imports or code-splitted chunks not in 'chunks' array are ignored.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Check that the chunk name in 'chunks' matches an actual entry/async chunk, and that external files exist.","cause":"Attempting to replace content on a non-existent chunk or external file.","error":"Cannot read property 'source' of undefined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}