Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to define if sourcemaps should be generated fixes #42 #48

Merged
merged 1 commit into from
Mar 6, 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
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