Skip to content
This repository has been archived by the owner on Nov 20, 2019. It is now read-only.

Add include option - whitelist for matching assets #22

Merged
merged 1 commit into from
Feb 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,11 @@ Path to the actual service worker implementation.
- `filename`, *string*, default `'sw.js'`:
Relative (from the webpack's config `output.path`) output path for emitted script.
- `excludes`, *array*, default `['**/.*', '**/*.map']`:
Excludes matches assets from being added to the `serviceWorkerOption.assets` variable.
Exclude matched assets from being added to the `serviceWorkerOption.assets` variable. (Blacklist)
- `includes`, *array*, default `['**/*']`:
Include matched assets added to the `serviceWorkerOption.assets` variable. (Whitelist)
- `publicPath`, *string*, default `''`:
specifies the public URL address of the output files when referenced in a browser.
Specifies the public URL address of the output files when referenced in a browser.
- `template`, *function*, default noop:
This callback function can be used to inject statically generated service worker.
It's taking a `serviceWorkerOption` argument and must return a promise.
Expand Down
11 changes: 11 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export default class ServiceWorkerPlugin {
this.options = Object.assign({
publicPath: '',
excludes: ['**/.*', '**/*.map'],
includes: ['**/*'],
entry: null,
filename: 'sw.js',
template: () => Promise.resolve(''),
Expand Down Expand Up @@ -142,6 +143,16 @@ export default class ServiceWorkerPlugin {
});
}

const includes = this.options.includes;

if (includes.length > 0) {
assets = assets.filter((assetCurrent) => {
return includes.some((glob) => {
return minimatch(assetCurrent, glob);
});
});
}

assets = validatePaths(assets, this.options);

const minify = (compiler.options.plugins || []).some((plugin) => {
Expand Down