Skip to content
This repository was archived by the owner on Sep 19, 2020. It is now read-only.

Commit 99bf35e

Browse files
author
Spencer Elliott
committed
Add loader
1 parent e1be421 commit 99bf35e

File tree

4 files changed

+65
-0
lines changed

4 files changed

+65
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/node_modules/

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,32 @@
11
# regexp-replace-loader
22
A 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".

index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
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+
};

package.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
}

0 commit comments

Comments
 (0)