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
70.8
Supply Chain
98.3
Quality
76.9
Maintenance
100
Vulnerability
100
License
Cumulative downloads
Total Downloads
Last day
100%
2
Compared to previous day
Last week
100%
2
Compared to previous week
Last month
-54.5%
5
Compared to previous month
Last year
0%
206
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.