
Security News
Django Joins curl in Pushing Back on AI Slop Security Reports
Django has updated its security policies to reject AI-generated vulnerability reports that include fabricated or unverifiable content.
content-replacer-loader
Advanced tools
A NodeJS webpack loader to replace strings in specific file content or replace the file content before passing to its appropriate loader. Supports .js, .jsx, .ts, .tsx, .html, .htm, and .css.
content-replacer-loader
content-replacer-loader
is a NodeJS webpack loader designed to replace strings in any specific file content or replace the file content with another one before passing it to its appropriate loader. This loader currently supports .js
, .jsx
, .ts
, .tsx
, .html
, .htm
, and .css
file extensions.
To install content-replacer-loader
, you need to use npm or yarn:
npm install content-replacer-loader --save-dev
or
yarn add content-replacer-loader --dev
To use content-replacer-loader
in your webpack configuration, add it to the module.rules
section of your webpack.config.js
:
const path = require('path');
module.exports = {
// Your other configurations...
module: {
rules: [
{
test: /\.(js|jsx|ts|tsx|html|htm|css)$/,
use: [
{
loader: 'content-replacer-loader',
options: {
// Your options here
}
}
]
}
]
}
};
The loader supports options conforming to the IPathOptions
interface. These options allow you to specify the content to be replaced or searched and replaced.
IPathOptions
Interfaceinterface IPathOptions {
entireContent?: {
startsWith?: IEntireContent | IEntireContent[];
includes?: IEntireContent | IEntireContent[];
endsWith?: IEntireContent | IEntireContent[];
};
findAndReplace?: {
startsWith?: IFindAndReplace | IFindAndReplace[];
includes?: IFindAndReplace | IFindAndReplace[];
endsWith?: IFindAndReplace | IFindAndReplace[];
};
}
IEntireContent
Interfaceinterface IEntireContent {
pathOrExt: string;
content: string;
caseInSensitivePathMatch?: boolean;
}
IFindAndReplace
Interfaceinterface IFindAndReplace {
pathOrExt: string;
find: { replace: string; find: string | RegExp }[];
firstReplace?: boolean;
caseInSensitivePathMatch?: boolean;
caseInSensitive?: boolean;
}
Here's an example configuration that demonstrates how to use the content-replacer-loader
with the available options:
module.exports = {
// Your other configurations...
module: {
rules: [
{
test: /\.(js|jsx|ts|tsx|html|htm|css)$/,
use: [
{
loader: 'content-replacer-loader',
options: {
entireContent: {
startsWith: {
pathOrExt: '.html',
content: '<!DOCTYPE html>'
},
includes: [
{
pathOrExt: '.js',
content: 'use strict'
},
{
pathOrExt: '.css',
content: '@charset "UTF-8";'
}
],
endsWith: {
pathOrExt: 'index.ts',
content: 'export {}'
}
},
findAndReplace: {
includes: [
{
pathOrExt: 'button.js',
find: [
{ find: 'var', replace: 'let' },
{ find: /console\.log\(/g, replace: 'debug.log(' }
],
caseInSensitive: true
}
]
}
}
}
]
}
]
}
};
This project is licensed under the MIT License.
Contributions are welcome! Please open an issue or submit a pull request with any improvements or bug fixes.
If you encounter any issues or have any questions, feel free to open an issue on the project's GitHub page.
Thanks to the open-source community for the inspiration and support in developing this project.
FAQs
A NodeJS webpack loader to replace strings in specific file content or replace the file content before passing to its appropriate loader. Supports .js, .jsx, .ts, .tsx, .html, .htm, and .css.
We found that content-replacer-loader demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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
Django has updated its security policies to reject AI-generated vulnerability reports that include fabricated or unverifiable content.
Security News
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Security News
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.