Skip to content

Commit 3d6123f

Browse files
committed
1.4.0 Provide context to replacement function
1 parent 999d710 commit 3d6123f

File tree

5 files changed

+16
-6
lines changed

5 files changed

+16
-6
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 1.4.0 (23 Apr, 2021)
2+
3+
* [#19](https://github.com/vyushin/file-replace-loader/issues/19) Provide context to replacement function
4+
15
## 1.3.1 (02 Oct, 2020)
26

37
* Fix bug when the loader works idle if replacement returns the same path

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ This case throw an error because file-replace-loader should be last in list.
236236
| Option | Type | Required | Default | Possible values
237237
| ------------ | ------------- | ------------- | ------------- | -------------
238238
| `condition`<br/>Condition to replace | `string`&#124;`boolean` | no | `'if-replacement-exists'` | `true`,<br/>`false`,<br/>`'always'`,<br/>`'never'`,<br/>`'if-replacement-exists'`,<br/>`'if-source-is-empty'`
239-
| `replacement`<br/>Replacement file | `string`&#124;`Function` | yes | — | Full path to file or function returning full path to file
239+
| `replacement`<br/>Replacement file | `string`&#124;`function (resourcePath, options)` | yes | — | Full path to file or function returning full path to file
240240
| `async`<br/>Asynchronous file reading | `boolean` | no | `true` | `true`,<br/>`false`
241241
| `progress`<br/>Progress output | `boolean` | no | `IS_DEBUG_MODE == true or IS_PROGRESS_MODE == true` | `true`,<br/>`false`
242242

dist/index.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,13 @@ function _default(source) {
149149
var options = getOptions(this);
150150
var isAsync = options && options.async === true;
151151
var callback = isAsync === true && this.async() || null;
152+
var context = this.context;
152153

153154
var replacement = function replacement(resourcePath) {
154-
return options.replacement instanceof Function ? options.replacement(resourcePath) || null : options.replacement;
155+
var opts = {
156+
context
157+
};
158+
return options.replacement instanceof Function ? options.replacement(resourcePath, opts) || null : options.replacement;
155159
};
156160

157161
var progress = progressFactory(options);

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "file-replace-loader",
3-
"version": "1.3.2",
3+
"version": "1.4.0",
44
"description": "file-replace-loader is webpack loader that allows you replace files in compile time",
55
"author": "Evgeny Vyushin <[email protected]> (https://github.com/vyushin)",
66
"contributors": [

src/index.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,11 @@ export default function(source) {
118118
const options = getOptions(this);
119119
const isAsync = options && options.async === true;
120120
const callback = isAsync === true && this.async() || null;
121-
const replacement = (resourcePath) => (
122-
options.replacement instanceof Function ? options.replacement(resourcePath) || null : options.replacement
123-
);
121+
const context = this.context;
122+
const replacement = (resourcePath) => {
123+
const opts = { context };
124+
return options.replacement instanceof Function ? options.replacement(resourcePath, opts) || null : options.replacement
125+
};
124126
const progress = progressFactory(options);
125127

126128
/**

0 commit comments

Comments
 (0)