
Security News
Axios Maintainer Confirms Social Engineering Attack Behind npm Compromise
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.
@clayne/string-replace-loader
Advanced tools
Perform replacements (plain and regular expression) in the contents loaded by the loader.
$ npm install --save-dev string-replace-loader
In general, loader allows to perform replacements in a way String.prototype.replace() does (loader uses it internally). For instance, it means that if you want to replace all occurences, you should use RegExp in query.search with g flag in query.flags, etc.
In your webpack.config.js:
module.exports = {
// ...
module: {
loaders: [
{
test: /fileInWhichJQueryIsUndefined\.js$/,
loader: 'string-replace',
query: {
search: 'jQuery',
replace: 'window.$'
}
}
]
}
}
To achieve regular expression replacement you should specify the flags query param
(as an empty string if you do not want any flags). In this case, search and flags are being
passed to the RegExp constructor.
In your webpack.config.js:
module.exports = {
// ...
module: {
loaders: [
{
test: /fileInWhichJQueryIsUndefined\.js$/,
loader: 'string-replace',
query: {
search: 'jquery',
replace: 'window.$',
flags: 'i'
}
}
]
}
}
Also, you can pass an array of search-replace pairs this way:
In your webpack.config.js:
module.exports = {
// ...
module: {
loaders: [
{
test: /\.js$/,
loader: 'string-replace',
query: {
multiple: [
{ search: 'jQuery', replace: 'window.$' },
{ search: '_', replace: 'window.lodash' }
]
}
}
]
}
}
Feel free to open issues to propose stuff and participate. Pull requests are also welcome.
FAQs
Replace loader for Webpack
The npm package @clayne/string-replace-loader receives a total of 11 weekly downloads. As such, @clayne/string-replace-loader popularity was classified as not popular.
We found that @clayne/string-replace-loader demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.