Skip to content

Commit

Permalink
feat(mobile): add ServiceWorker generation to build process and index
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffbcross committed May 12, 2016
1 parent 51569ce commit 04593eb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
6 changes: 2 additions & 4 deletions addon/ng2/blueprints/ng2/files/__path__/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,15 @@
<link rel="{{rel}}" {{#if sizes}}sizes="{{sizes}}" {{/if}}href="{{href}}">
{{/each}}

<!-- Service worker support is disabled by default.
Install the worker script and uncomment to enable.
Only enable service workers in production.
{{#if environment.production}}
<script type="text/javascript">
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/worker.js').catch(function(err) {
console.log('Error installing service worker: ', err);
});
}
</script>
-->
{{/if}}
<% } %>
</head>
<body>
Expand Down
2 changes: 2 additions & 0 deletions addon/ng2/blueprints/ng2/files/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
},
"devDependencies": {<% if(isMobile) { %>
"@angular/platform-server": "2.0.0-rc.1",
"angular2-broccoli-prerender": "^0.11.0",
"angular2-service-worker": "0.1.11",
"angular2-universal":"^0.100.3",
"angular2-universal-polyfills": "^0.4.1",
"preboot": "^2.0.10",<% } %>
Expand Down
12 changes: 12 additions & 0 deletions lib/broccoli/angular2-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,14 @@ class Angular2App extends BroccoliPlugin {
merged = this._getBundleTree(merged);
}

if (this.ngConfig.apps[0].mobile) {
var ServiceWorkerPlugin = require('angular2-service-worker').ServiceWorkerPlugin;
var swTree = new ServiceWorkerPlugin(merged);
merged = BroccoliMergeTrees([merged, swTree], {
overwrite: true
});
}

return new BroccoliFunnel(merged, {
destDir: this._destDir,
overwrite: true
Expand Down Expand Up @@ -348,6 +356,10 @@ class Angular2App extends BroccoliPlugin {
var vendorNpmFiles = [
];

if (this.ngConfig.apps[0].mobile) {
vendorNpmFiles.push('angular2-service-worker/dist/worker.js')
}

if (this._options.vendorNpmFiles) {
vendorNpmFiles = vendorNpmFiles.concat(this._options.vendorNpmFiles);
}
Expand Down

0 comments on commit 04593eb

Please sign in to comment.