Skip to content

Commit

Permalink
feat: add importScriptsTransform option
Browse files Browse the repository at this point in the history
  • Loading branch information
emattias committed Dec 16, 2019
1 parent d321d2f commit 440f1f1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@ If you need to customize **ember-cli-workbox configuration** you can do it like
ENV['ember-cli-workbox'] = {
enabled: environment !== 'test',
debug: true,
autoRegister: true
autoRegister: true,
importScriptsTransform: (importScripts) => {
return importScripts.map((importScript) => {
return `https://example-cdn.com/${importScript}`;
}
}
};
```
Expand All @@ -48,6 +53,7 @@ ENV['ember-cli-workbox'] = {
| `enabled` | `Boolean` | Addon is enabled. Default to true on production builds |
| `debug` | `Boolean` | Log serviceworker states (registering, updating, etc) |
| `autoRegister` | `Boolean` | Enable the sw registration before initializing the application |
| `importScriptsTransform` | `Function` | Allows for transformation of array sent to workbox [importScripts](https://developers.google.com/web/tools/workbox/modules/workbox-build#generateSW-importScripts) |
You can further customize ember-cli-workbox by setting **workbox configurations** in your environment.js file:
Expand Down
4 changes: 4 additions & 0 deletions lib/broccoli-workbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ BroccoliWorkbox.prototype.build = function() {

workboxOptions.importScripts = filesToIncludeInSW;

if (this.options.importScriptsTransform) {
workboxOptions.importScripts = this.options.importScriptsTransform(workboxOptions.importScripts);
}

return cleanPromise.then(() =>
workboxBuild.generateSW(workboxOptions).then(({ count, size }) => {
debug(blue('Service worker successfully generated.'));
Expand Down

0 comments on commit 440f1f1

Please sign in to comment.