import swPrecache from 'sw-precache';
import { resolve } from 'path';
import fs from 'fs';
import uglifyJs from 'uglify-js';
import webpackConfig from './webpack.config.prod';
import pkg from './package.json';

const publicDir = webpackConfig.output.path;

swPrecache.generate({
  cacheId: pkg.name,
  dontCacheBustUrlsMatching: /./,
  dynamicUrlToDependencies: {
    '/': [resolve(__dirname, 'views', 'index.ejs')]
  },
  staticFileGlobs: [
    `${publicDir}/bundle.*.{js,css}`,
    `${publicDir}/vendor.*.{js,css}`
  ],
  navigateFallback: '/',
  navigateFallbackWhitelist: [
    /^\/posts\//,
    /^\/about/
  ],
  stripPrefix: publicDir,
  runtimeCaching: [{
    urlPattern: /api/,
    handler: 'networkFirst'
  }]
}, (error, serviceWorkerString) => {
  if (error) {
    return console.log(error);
  }
  fs.writeFile(`${publicDir}/sw.js`, uglifyJs.minify(serviceWorkerString).code, (err) => {
    if (err) {
      return console.log(err);
    }
  });
});

@@ -717,18 +717,16 @@
 %7D%5D%0A%7D
-, (error, 
+).then((
 serv
@@ -751,58 +751,8 @@
 %3E %7B%0A
-  if (error) %7B%0A    return console.log(error);%0A  %7D%0A
   fs

Update precache