Skip to content

Commit

Permalink
Merge pull request #20 from vyushin/1.4.0
Browse files Browse the repository at this point in the history
Release 1.4.0
  • Loading branch information
vyushin authored Apr 22, 2021
2 parents 999d710 + 3d6123f commit cf8c8b7
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.4.0 (23 Apr, 2021)

* [#19](https://github.com/vyushin/file-replace-loader/issues/19) Provide context to replacement function

## 1.3.1 (02 Oct, 2020)

* Fix bug when the loader works idle if replacement returns the same path
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ This case throw an error because file-replace-loader should be last in list.
| Option | Type | Required | Default | Possible values
| ------------ | ------------- | ------------- | ------------- | -------------
| `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'`
| `replacement`<br/>Replacement file | `string`&#124;`Function` | yes | — | Full path to file or function returning full path to file
| `replacement`<br/>Replacement file | `string`&#124;`function (resourcePath, options)` | yes | — | Full path to file or function returning full path to file
| `async`<br/>Asynchronous file reading | `boolean` | no | `true` | `true`,<br/>`false`
| `progress`<br/>Progress output | `boolean` | no | `IS_DEBUG_MODE == true or IS_PROGRESS_MODE == true` | `true`,<br/>`false`

Expand Down
6 changes: 5 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,13 @@ function _default(source) {
var options = getOptions(this);
var isAsync = options && options.async === true;
var callback = isAsync === true && this.async() || null;
var context = this.context;

var replacement = function replacement(resourcePath) {
return options.replacement instanceof Function ? options.replacement(resourcePath) || null : options.replacement;
var opts = {
context
};
return options.replacement instanceof Function ? options.replacement(resourcePath, opts) || null : options.replacement;
};

var progress = progressFactory(options);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "file-replace-loader",
"version": "1.3.2",
"version": "1.4.0",
"description": "file-replace-loader is webpack loader that allows you replace files in compile time",
"author": "Evgeny Vyushin <[email protected]> (https://github.com/vyushin)",
"contributors": [
Expand Down
8 changes: 5 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,11 @@ export default function(source) {
const options = getOptions(this);
const isAsync = options && options.async === true;
const callback = isAsync === true && this.async() || null;
const replacement = (resourcePath) => (
options.replacement instanceof Function ? options.replacement(resourcePath) || null : options.replacement
);
const context = this.context;
const replacement = (resourcePath) => {
const opts = { context };
return options.replacement instanceof Function ? options.replacement(resourcePath, opts) || null : options.replacement
};
const progress = progressFactory(options);

/**
Expand Down

0 comments on commit cf8c8b7

Please sign in to comment.