Registry / devops / string-replace-loader

string-replace-loader

JSON →
library3.3.0jsnpmunverified

A Webpack loader that performs string or regex replacements on file contents during the build process. Version 3.3.0 is the latest stable release, with occasional minor/patch updates. It supports plain string replacement, RegExp replacement (via string with flags or RegExp object), multiple replacements in a single rule, callback-based dynamic replacement, and strict mode. Key differentiators: flexible configuration similar to String.prototype.replace, array of replacements, strict mode to ensure replacements occurred. Compared to alternatives like `replace-in-file-webpack-plugin` or `webpack-replace-loader`, this loader integrates directly into the loader chain and works per-file based on test patterns. Requires Webpack 5+ and Node.js 4+.

devopshttp-networking
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

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

This is a Webpack loader, not a regular library. It is referenced by the 'loader' field in Webpack config rules. No import statement needed; just configure in webpack.config.js.

module.exports = { module: { rules: [ { test: /\.js$/, loader: 'string-replace-loader', options: { search: 'foo', replace: 'bar' } } ] } }

Demonstrates basic replacement of 'jQuery' with 'window.$' in all .js files.

// webpack.config.js module.exports = { module: { rules: [ { test: /\.js$/, loader: 'string-replace-loader', options: { search: 'jQuery', replace: 'window.$' } } ] } };
Debug
Known footguns
breakingVersion 3.0.0 drops support for Webpack 4 and lower. Using with Webpack 4 will cause errors.
breakingVersion 2.0.0 drops support for Node.js 3 and lower. Older Node versions will fail to load the loader.
deprecatedThe loader uses String.prototype.replace internally; for global replacements, you must use a regex with the 'g' flag. Missing 'g' flag replaces only first occurrence.
gotchaWhen using options.search as a string and options.flags, special regex characters in the search string must be escaped. If you intend a literal string, use the plain replacement method without flags.
gotchaThe multiple replacements option processes replacements in parallel? No, they are applied sequentially. This can cause unexpected results if later replacements match strings introduced by earlier ones.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
17 hits · last 30 days
gptbot
4
ahrefsbot
4
amazonbot
4
bytedance
4
script
1
Resources