Registry / devops / webpack-string-replacer

webpack-string-replacer

JSON →
library0.0.20jsnpmunverified

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.

npm install webpack-string-replacer
INSTALL
IMPORT
SIG · WEBPACK-STRING-REP
W
webpack-string-replacer
devopsjavascriptv0.0.20
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

WebpackStringReplacer
const WebpackStringReplacer = require('webpack-string-replacer');
import WebpackStringReplacer from 'webpack-string-replacer';
CommonJS default export; ESM import may not work due to lack of 'default' export.
WebpackStringReplacer
import WebpackStringReplacer = require('webpack-string-replacer');
TypeScript import using 'require' syntax.
WebpackStringReplacer
const { WebpackStringReplacer } = require('webpack-string-replacer');
const WebpackStringReplacer = require('webpack-string-replacer').WebpackStringReplacer;
Named export is not available; only default export.

Shows basic usage: require the plugin, add to webpack plugins with a rule to replace a token in a specific file.

const WebpackStringReplacer = require('webpack-string-replacer'); // webpack config module.exports = { plugins: [ new WebpackStringReplacer({ rules: [{ fileInclude: 'targetFile.js', replacements: [{ pattern: 'MY_API_TOKEN', patternMatchCount: { min: 4 }, replacement: 'lPP5BxQESO6VU4aUcKJLFg', }], }], }), ], };
Debug
Known issues
gotchaWhen using applyStage: 'loader' or 'optimizeModules', do not use outputFileInclude/outputFileExclude; they are only for 'optimizeChunkAssets'.
fix
Use fileInclude/fileExclude for source stages, outputFileInclude/outputFileExclude for chunk stage.
affects: all
gotchaWhen using applyStage: 'optimizeChunkAssets', do not use fileInclude/fileExclude; they are only for source stages.
fix
Use outputFileInclude/outputFileExclude instead.
affects: all
gotchaThe plugin does not have a default export; using import syntax may fail.
fix
Use require('webpack-string-replacer') or TypeScript import with '= require'.
affects: all
gotchaPattern with regex flags (e.g., /g) is supported but may not behave as expected if not global.
fix
Ensure pattern flags match intended behavior; test with a simple string first.
affects: all
Errors
Common errors & fixes
TypeError: WebpackStringReplacer is not a constructor
Using import statement with ES modules in a CommonJS project.
fix
Replace `import WebpackStringReplacer from 'webpack-string-replacer'` with `const WebpackStringReplacer = require('webpack-string-replacer')`.
ValidationError: Match count for pattern 'MY_API_TOKEN' not met (min: 4, actual: 0)
patternMatchCount.min is set but the pattern never appears in the file.
fix
Verify the pattern exists in the file or reduce/remove the min requirement.
Error: Plugin cannot use fileInclude and outputFileInclude simultaneously
Mixing stage-specific options incorrectly.
fix
Choose one stage and use the corresponding include/exclude options.
Module not found: Error: Can't resolve 'webpack-string-replacer'
Package not installed or not in node_modules.
fix
Run `npm install --save-dev webpack-string-replacer` from project root.
Upgrade
Version history
0.0.20latest on npm
Audit
Dependencies
webpackrequiredPeer dependency; plugin requires webpack compilation hooks.
Agent activity
4 hits · last 30 days
node
4
Resources
webpack-string-replacer — npm install webpack-string-replacer · libregistry