Skip to content

Commit

Permalink
feat: add support for contextDependencies in the {Object} interfa…
Browse files Browse the repository at this point in the history
…ce (`options.contextDependencies`) (#23)

* Add support for marking context dependencies in the object interface

* Add contextDependencies to dependencies.js test fixture
  • Loading branch information
raleksandar authored and joshwiens committed Nov 19, 2017
1 parent a59cd0f commit 78aa6fe
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ Property | Type | Description
`sourceMap` | [`SourceMap`](https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit) | **Optional**. Will be passed to the next loader or to webpack.
`ast``any` | **Optional**. An [Abstract Syntax Tree](https://en.wikipedia.org/wiki/Abstract_syntax_tree) that will be passed to the next loader. Useful to speed up the build time if the next loader uses the same AST.
`dependencies` | `Array<string>` | **Default: `[]`**. An array of absolute, native paths to file dependencies that need to be watched for changes.
`contextDependencies` | `Array<string>` | **Default: `[]`**. An array of absolute, native paths to directory dependencies that need to be watched for changes.
`cacheable` | `boolean` | **Default: `false`**. Flag whether the code can be re-used in watch mode if none of the `dependencies` have changed.

### Loader Options
Expand Down
4 changes: 4 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ function processResult(loaderContext, result) {

(result.dependencies || [])
.forEach(dep => loaderContext.addDependency(dep));

(result.contextDependencies || [])
.forEach(dep => loaderContext.addContextDependency(dep));

// Defaults to false which is a good default here because we assume that
// results tend to be not cacheable when this loader is necessary
loaderContext.cacheable(Boolean(result.cacheable));
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/dependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ function dependencies() {
require.resolve('./args.js'),
require.resolve('./simple.js'),
],
contextDependencies: [
__dirname,
],
code: '',
};
}
Expand Down

0 comments on commit 78aa6fe

Please sign in to comment.