{"id":27548,"library":"webpack-string-replacer","title":"Webpack String Replacer","description":"Webpack plugin to replace strings in modules at configurable build stages. Version 0.0.20 supports three apply stages (loader, optimizeModules, optimizeChunkAssets) and match-count requirements with min/max constraints. Provides TypeScript types, inherited rule/replacement defaults, and validation logging. Differentiates from simple find-and-replace by allowing stage-specific application and output-file-based filtering.","status":"active","version":"0.0.20","language":"javascript","source_language":"en","source_url":"https://github.com/Venryx/webpack-string-replacer","tags":["javascript","webpack","plugin","webpack-plugin","bundle","content","text","string","token","typescript"],"install":[{"cmd":"npm install webpack-string-replacer","lang":"bash","label":"npm"},{"cmd":"yarn add webpack-string-replacer","lang":"bash","label":"yarn"},{"cmd":"pnpm add webpack-string-replacer","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency; plugin requires webpack compilation hooks.","package":"webpack","optional":false}],"imports":[{"note":"CommonJS default export; ESM import may not work due to lack of 'default' export.","wrong":"import WebpackStringReplacer from 'webpack-string-replacer';","symbol":"WebpackStringReplacer","correct":"const WebpackStringReplacer = require('webpack-string-replacer');"},{"note":"TypeScript import using 'require' syntax.","symbol":"WebpackStringReplacer","correct":"import WebpackStringReplacer = require('webpack-string-replacer');"},{"note":"Named export is not available; only default export.","wrong":"const WebpackStringReplacer = require('webpack-string-replacer').WebpackStringReplacer;","symbol":"WebpackStringReplacer","correct":"const { WebpackStringReplacer } = require('webpack-string-replacer');"}],"quickstart":{"code":"const WebpackStringReplacer = require('webpack-string-replacer');\n\n// webpack config\nmodule.exports = {\n  plugins: [\n    new WebpackStringReplacer({\n      rules: [{\n        fileInclude: 'targetFile.js',\n        replacements: [{\n          pattern: 'MY_API_TOKEN',\n          patternMatchCount: { min: 4 },\n          replacement: 'lPP5BxQESO6VU4aUcKJLFg',\n        }],\n      }],\n    }),\n  ],\n};","lang":"javascript","description":"Shows basic usage: require the plugin, add to webpack plugins with a rule to replace a token in a specific file."},"warnings":[{"fix":"Use fileInclude/fileExclude for source stages, outputFileInclude/outputFileExclude for chunk stage.","message":"When using applyStage: 'loader' or 'optimizeModules', do not use outputFileInclude/outputFileExclude; they are only for 'optimizeChunkAssets'.","severity":"gotcha","affected_versions":"all"},{"fix":"Use outputFileInclude/outputFileExclude instead.","message":"When using applyStage: 'optimizeChunkAssets', do not use fileInclude/fileExclude; they are only for source stages.","severity":"gotcha","affected_versions":"all"},{"fix":"Use require('webpack-string-replacer') or TypeScript import with '= require'.","message":"The plugin does not have a default export; using import syntax may fail.","severity":"gotcha","affected_versions":"all"},{"fix":"Ensure pattern flags match intended behavior; test with a simple string first.","message":"Pattern with regex flags (e.g., /g) is supported but may not behave as expected if not global.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Replace `import WebpackStringReplacer from 'webpack-string-replacer'` with `const WebpackStringReplacer = require('webpack-string-replacer')`.","cause":"Using import statement with ES modules in a CommonJS project.","error":"TypeError: WebpackStringReplacer is not a constructor"},{"fix":"Verify the pattern exists in the file or reduce/remove the min requirement.","cause":"patternMatchCount.min is set but the pattern never appears in the file.","error":"ValidationError: Match count for pattern 'MY_API_TOKEN' not met (min: 4, actual: 0)"},{"fix":"Choose one stage and use the corresponding include/exclude options.","cause":"Mixing stage-specific options incorrectly.","error":"Error: Plugin cannot use fileInclude and outputFileInclude simultaneously"},{"fix":"Run `npm install --save-dev webpack-string-replacer` from project root.","cause":"Package not installed or not in node_modules.","error":"Module not found: Error: Can't resolve 'webpack-string-replacer'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}