Skip to content

Commit

Permalink
Merge 1219e59 into 29905ad
Browse files Browse the repository at this point in the history
  • Loading branch information
priyank-p committed Dec 29, 2017
2 parents 29905ad + 1219e59 commit 4964644
Show file tree
Hide file tree
Showing 5 changed files with 462 additions and 9 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -55,6 +55,7 @@
"nwmatcher": "1.3.6",
"phantomjs-prebuilt": "2.1.14",
"svgo": "0.7.2",
"sw-precache-webpack-plugin": "0.11.4",
"swagger-parser": "3.4.1",
"tslint": "5.3.2",
"webpack-dev-server": "2.4.1",
Expand Down
1 change: 1 addition & 0 deletions templates/zerver/home.html
Expand Up @@ -134,5 +134,6 @@ <h4>{{ _('Nobody has talked about that yet!') }}</h4>
{% include "zerver/message_history.html" %}
{% include "zerver/delete_message.html" %}
{% include "zerver/compose.html" %}
{% include "zerver/service_worker.html" %}
<div id="notifications-area">
</div>
10 changes: 10 additions & 0 deletions templates/zerver/service_worker.html
@@ -0,0 +1,10 @@
<script>
if ('serviceWorker' in navigator) {
window.addEventListener('load', function() {
navigator.serviceWorker.register('/static/webpack-bundles/zulip-sw.js')
.catch(function(err) {
console.log('ServiceWorker registration failed: ', err);
});
});
}
</script>
13 changes: 13 additions & 0 deletions tools/webpack.config.ts
@@ -1,6 +1,7 @@
import { resolve } from 'path';
import * as BundleTracker from 'webpack-bundle-tracker';
import * as webpack from 'webpack';
import * as SWPrecacheWebpackPlugin from 'sw-precache-webpack-plugin';

const assets = require('./webpack.assets.json');

Expand All @@ -11,8 +12,18 @@ interface Config extends webpack.Configuration {
}
}

const SW_PRECACHE_CONFIG = {
minify: true,
cacheId: 'zulip-sw',
filename: 'zulip-sw.js',
staticFileGlobs: ['*.js', '*.css'],
mergeStaticsConfig: true,
staticFileGlobsIgnorePatterns: [/.*\.html/, /.*\.map/],
};

export default (env?: string) : Config => {
const production: boolean = env === "production";

let config: Config = {
context: resolve(__dirname, "../"),
entry: assets,
Expand Down Expand Up @@ -125,5 +136,7 @@ export default (env?: string) : Config => {
},
};
}

config.plugins.push(new SWPrecacheWebpackPlugin(SW_PRECACHE_CONFIG));
return config;
};

0 comments on commit 4964644

Please sign in to comment.