Skip to content

Commit bb1fd01

Browse files
committed
version 2.1.1; readme updated
1 parent a6555e1 commit bb1fd01

File tree

3 files changed

+23
-19
lines changed

3 files changed

+23
-19
lines changed

README.md

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,26 @@ Support for Node v3 and lower was dropped, but you can install and use the loade
1313

1414
## Usage:
1515

16-
In general, loader allows to perform replacements in a way [String.prototype.replace()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace) does (loader uses it internally).
17-
For instance, it means that if you want to replace all occurrences, you should use RegExp-like string in `query.search` with `g` flag in `query.flags`, etc.
16+
Loader allows to perform replacements in a way [String.prototype.replace()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace) does (loader uses it internally).
17+
It means that if you want to replace all occurrences, you should use RegExp-like string in `options.search` with `g` flag in `options.flags`, etc.
1818

1919
### Plain replacement:
2020

21+
Plain string replacement, no need to escape RegEx special characters.
22+
2123
In your `webpack.config.js`:
2224

2325
```javascript
2426
module.exports = {
2527
// ...
2628
module: {
27-
loaders: [
29+
rules: [
2830
{
2931
test: /fileInWhichJQueryIsUndefined\.js$/,
3032
loader: 'string-replace-loader',
31-
query: {
32-
search: 'jQuery',
33-
replace: 'window.$'
33+
options: {
34+
search: '$',
35+
replace: 'window.jQuery',
3436
}
3537
}
3638
]
@@ -40,23 +42,24 @@ module.exports = {
4042

4143
### RegEx replacement:
4244

43-
To achieve regular expression replacement you should specify the `flags` query param
45+
To achieve regular expression replacement you should specify the `flags` option
4446
(as an empty string if you do not want any flags). In this case, `search` and `flags` are being
45-
passed to the [RegExp](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp) constructor.
47+
passed to the [RegExp](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp) constructor
48+
and this means that you should escape RegEx special characters in `search` if you want it to be replaced as a string.
4649

4750
In your `webpack.config.js`:
4851

4952
```javascript
5053
module.exports = {
5154
// ...
5255
module: {
53-
loaders: [
56+
rules: [
5457
{
5558
test: /fileInWhichJQueryIsUndefined\.js$/,
5659
loader: 'string-replace-loader',
57-
query: {
58-
search: 'jquery',
59-
replace: 'window.$',
60+
options: {
61+
search: '\$',
62+
replace: 'window.jQuery',
6063
flags: 'i'
6164
}
6265
}
@@ -75,11 +78,11 @@ In your `webpack.config.js`:
7578
module.exports = {
7679
// ...
7780
module: {
78-
loaders: [
81+
rules: [
7982
{
8083
test: /\.js$/,
8184
loader: 'string-replace-loader',
82-
query: {
85+
options: {
8386
multiple: [
8487
{ search: 'jQuery', replace: 'window.$' },
8588
{ search: '_', replace: 'window.lodash' }
@@ -93,19 +96,20 @@ module.exports = {
9396

9497
### Strict mode replacement:
9598

96-
You can set strict mode to ensure that the replacement was done:
99+
You can enable strict mode to ensure that the replacement was performed.
100+
Loader will throw exception if nothing was replaced or if `search` or `replace` options were not specified.
97101

98102
In your `webpack.config.js`:
99103

100104
```javascript
101105
module.exports = {
102106
// ...
103107
module: {
104-
loaders: [
108+
rules: [
105109
{
106110
test: /fileInWhichJQueryIsUndefined\.js$/,
107111
loader: 'string-replace-loader',
108-
query: {
112+
options: {
109113
search: 'jQuery',
110114
replace: 'window.$',
111115
strict: true

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "string-replace-loader",
3-
"version": "2.1.0",
3+
"version": "2.1.1",
44
"description": "Replace loader for Webpack",
55
"keywords": [
66
"webpack",

0 commit comments

Comments
 (0)