Skip to content

Commit

Permalink
Add option to define if sourcemaps should be generated fixes #42 (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
urbany authored and jkleinsc committed Mar 6, 2017
1 parent 37164a8 commit bfd4db5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ By default the service worker will be generated for production builds and the se
ENV.serviceWorker = {
enabled: true,
debug: true,
sourcemaps: true,
precacheURLs: ['/mystaticresource'],
excludePaths: ['test.*', 'robots.txt',],
fallback: [
Expand All @@ -43,6 +44,7 @@ ENV.serviceWorker = {
The following options are available:
* **enabled** - Generate service worker. Defaults to true in production.
* **debug** - Display debug messages in console.
* **sourcemaps** - Boolean that defines if sourcemaps should be generated. Defaults to the same value of debug.
* **precacheURLs** - Array of URLs to precache and always serve from the cache. broccoli-serviceworker will automatically add all Ember app resources (e.g. files in dist) as precached URLs unless explictly excluded in excludePaths.
* **excludePaths** - Array of paths to exclude from precache. Files can be filtered using regular expressions.
```JavaScript
Expand Down
4 changes: 3 additions & 1 deletion lib/service-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var BroccoliServiceWorker = function BroccoliServiceWorker(inTree, options) {
this.cacheOnlyURLs = options.cacheOnlyURLs || [];
this.fastestURLs = options.fastestURLs || [];
this.debug = options.debug || false;
this.sourcemaps = options.sourcemaps || this.debug;
this.networkFirstURLs = options.networkFirstURLs || options.dynamicCache || [];
this.excludePaths = options.excludePaths || ['tests/*'];
this.fallback = options.fallback || [];
Expand Down Expand Up @@ -50,6 +51,7 @@ BroccoliServiceWorker.prototype.write = function(readTree, destDir) {
var cacheFirstURLs = this.cacheFirstURLs;
var cacheOnlyURLs = this.cacheOnlyURLs;
var debug = this.debug;
var sourcemaps = this.sourcemaps;
var networkFirstURLs = this.networkFirstURLs;
var fallback = this.fallback;
var rootURL = this.rootURL;
Expand Down Expand Up @@ -133,7 +135,7 @@ BroccoliServiceWorker.prototype.write = function(readTree, destDir) {
lines.push(getFileContents('log-debug.js'));
fs.writeFileSync(path.join(destDir, serviceWorkerFile), lines.join("\n"));
fs.writeFileSync(path.join(destDir, toolboxLocation), fs.readFileSync(swToolboxFile));
if (debug) {
if (sourcemaps) {
fs.writeFileSync(path.join(destDir, 'sw-toolbox.js.map'), fs.readFileSync(swToolboxMapFile));
}
});
Expand Down

0 comments on commit bfd4db5

Please sign in to comment.