diff --git a/README.md b/README.md index f3c0a28..222090d 100644 --- a/README.md +++ b/README.md @@ -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: [ @@ -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 diff --git a/lib/service-worker.js b/lib/service-worker.js index f2282bb..0a7555c 100644 --- a/lib/service-worker.js +++ b/lib/service-worker.js @@ -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 || []; @@ -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; @@ -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)); } });