This repository was archived by the owner on Sep 19, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +65
-0
lines changed Expand file tree Collapse file tree 4 files changed +65
-0
lines changed Original file line number Diff line number Diff line change 1+ /node_modules /
Original file line number Diff line number Diff line change 11# regexp-replace-loader
22A webpack loader to replace a regexp pattern with a string
3+
4+ ### Installation
5+
6+ ``` shell
7+ npm install regexp-replace-loader
8+ ```
9+
10+ ### Usage
11+
12+ ``` js
13+ // webpack.config.js
14+ ...
15+ module: {
16+ loaders: [
17+ {
18+ test: / \. js$ / ,
19+ loader: ' regexp-replace' ,
20+ query: {
21+ match: {
22+ pattern: ' ba(r|z)' ,
23+ flags: ' g'
24+ },
25+ replaceWith: ' foo'
26+ }
27+ }
28+ ]
29+ }
30+ ```
31+
32+ All instances of "bar" and "baz" should then be replaced by "foo".
Original file line number Diff line number Diff line change 1+ 'use strict' ;
2+
3+ var loaderUtils = require ( 'loader-utils' ) ;
4+
5+ module . exports = function ( source ) {
6+ var query = loaderUtils . parseQuery ( this . query ) ;
7+ var re = new RegExp ( query . match . pattern , query . match . flags ) ;
8+ return source . replace ( re , query . replaceWith ) ;
9+ } ;
Original file line number Diff line number Diff line change 1+ {
2+ "name" : " regexp-replace-loader" ,
3+ "version" : " 0.0.1" ,
4+ "description" : " A webpack loader to replace a regexp pattern with a string" ,
5+ "main" : " index.js" ,
6+ "scripts" : {
7+ "test" : " echo \" Error: no test specified\" && exit 1"
8+ },
9+ "repository" : {
10+ "type" : " git" ,
11+ "url" : " git+https://github.com/EventMobi/regexp-replace-loader.git"
12+ },
13+ "keywords" : [
14+ " webpack"
15+ ],
16+ "author" : " EventMobi <devs@eventmobi.com>" ,
17+ "license" : " MIT" ,
18+ "bugs" : {
19+ "url" : " https://github.com/EventMobi/regexp-replace-loader/issues"
20+ },
21+ "homepage" : " https://github.com/EventMobi/regexp-replace-loader#readme" ,
22+ "dependencies" : {
23+ "loader-utils" : " 0.2.11"
24+ }
25+ }
You can’t perform that action at this time.
0 commit comments