Gathering detailed insights and metrics for content-replacer-loader
Gathering detailed insights and metrics for content-replacer-loader
Gathering detailed insights and metrics for content-replacer-loader
Gathering detailed insights and metrics for content-replacer-loader
npm install content-replacer-loader
Typescript
Module System
Node Version
NPM Version
Total Downloads
256
Last Day
1
Last Week
3
Last Month
20
Last Year
256
Minified
Minified + Gzipped
Latest Version
1.0.1
Package Id
content-replacer-loader@1.0.1
Unpacked Size
24.24 kB
Size
6.17 kB
File Count
5
NPM Version
10.5.2
Node Version
20.13.1
Published on
Jul 27, 2024
Cumulative downloads
Total Downloads
Last Day
0%
1
Compared to previous day
Last Week
-50%
3
Compared to previous week
Last Month
185.7%
20
Compared to previous month
Last Year
0%
256
Compared to previous year
1
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:
1npm install content-replacer-loader --save-dev
or
1yarn 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
:
1const path = require('path'); 2 3module.exports = { 4 // Your other configurations... 5 module: { 6 rules: [ 7 { 8 test: /\.(js|jsx|ts|tsx|html|htm|css)$/, 9 use: [ 10 { 11 loader: 'content-replacer-loader', 12 options: { 13 // Your options here 14 } 15 } 16 ] 17 } 18 ] 19 } 20};
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
Interface1interface IPathOptions { 2 entireContent?: { 3 startsWith?: IEntireContent | IEntireContent[]; 4 includes?: IEntireContent | IEntireContent[]; 5 endsWith?: IEntireContent | IEntireContent[]; 6 }; 7 findAndReplace?: { 8 startsWith?: IFindAndReplace | IFindAndReplace[]; 9 includes?: IFindAndReplace | IFindAndReplace[]; 10 endsWith?: IFindAndReplace | IFindAndReplace[]; 11 }; 12}
IEntireContent
Interface1interface IEntireContent { 2 pathOrExt: string; 3 content: string; 4 caseInSensitivePathMatch?: boolean; 5}
IFindAndReplace
Interface1interface IFindAndReplace { 2 pathOrExt: string; 3 find: { replace: string; find: string | RegExp }[]; 4 firstReplace?: boolean; 5 caseInSensitivePathMatch?: boolean; 6 caseInSensitive?: boolean; 7}
Here's an example configuration that demonstrates how to use the content-replacer-loader
with the available options:
1module.exports = { 2 // Your other configurations... 3 module: { 4 rules: [ 5 { 6 test: /\.(js|jsx|ts|tsx|html|htm|css)$/, 7 use: [ 8 { 9 loader: 'content-replacer-loader', 10 options: { 11 entireContent: { 12 startsWith: { 13 pathOrExt: '.html', 14 content: '<!DOCTYPE html>' 15 }, 16 includes: [ 17 { 18 pathOrExt: '.js', 19 content: 'use strict' 20 }, 21 { 22 pathOrExt: '.css', 23 content: '@charset "UTF-8";' 24 } 25 ], 26 endsWith: { 27 pathOrExt: 'index.ts', 28 content: 'export {}' 29 } 30 }, 31 findAndReplace: { 32 includes: [ 33 { 34 pathOrExt: 'button.js', 35 find: [ 36 { find: 'var', replace: 'let' }, 37 { find: /console\.log\(/g, replace: 'debug.log(' } 38 ], 39 caseInSensitive: true 40 } 41 ] 42 } 43 } 44 } 45 ] 46 } 47 ] 48 } 49};
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.
No vulnerabilities found.
No security vulnerabilities found.