From 012632c1bb9899eeb9fbddbbcf743e95b1322548 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Sat, 14 Jul 2018 16:56:57 +0200 Subject: Added service worker for way better loading times --- webpack.mix.js | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 57 insertions(+), 2 deletions(-) (limited to 'webpack.mix.js') diff --git a/webpack.mix.js b/webpack.mix.js index 54a2883..36d9f82 100755 --- a/webpack.mix.js +++ b/webpack.mix.js @@ -1,4 +1,5 @@ let mix = require('laravel-mix'); +let SWPrecacheWebpackPlugin = require('sw-precache-webpack-plugin'); /* |-------------------------------------------------------------------------- @@ -12,15 +13,18 @@ let mix = require('laravel-mix'); */ mix.js('resources/assets/js/app.js', 'public/js') + .js('resources/assets/js/admin.js', 'public/js') .js('resources/assets/js/initial_key_gen.js', 'public/js') + .sass('resources/assets/sass/admin.scss', 'public/css') .sass('resources/assets/sass/app.scss', 'public/css') .sourceMaps() .browserSync({ files: [ 'public/css/*.css', 'public/js/*.js', - '**/*.blade.php' + //'**/*.blade.php' ], + notify: false, injectChanges: true, proxy: { target: '127.0.0.1:8000', @@ -31,4 +35,55 @@ mix.js('resources/assets/js/app.js', 'public/js') } } }) - .disableNotifications(); \ No newline at end of file + .disableNotifications().webpackConfig({ + plugins: [ + new SWPrecacheWebpackPlugin({ + cacheId: 'BEAM-Messenger', + filename: 'service-worker.js', + staticFileGlobs: [ + 'public/**/*.{css,js,eot,svg,ttf,woff,woff2,html}', // all compiled/public scripts + ], + minify: true, + stripPrefix: 'public/', + handleFetch: true, + maximumFileSizeToCacheInBytes: 20971520, + // dynamicUrlToDependencies: { + // '/': ['resources/views/writeMessage.blade.php'], + // '/profile': ['resources/views/profile.blade.php'], + // // TODO: add more for even better caching => ?? + // }, + staticFileGlobsIgnorePatterns: [/\.map$/, /mix-manifest\.json$/, /manifest\.json$/], + navigateFallback: '/', + importScripts: ['js/service-worker-ext.js'], + runtimeCaching: [{ + urlPattern: /^https:\/\/fonts\.googleapis\.com\//, + handler: 'cacheFirst' + }, + { + urlPattern: /^https:\/\/fonts\.gstatic\.com\//, + handler: 'cacheFirst' + }, + { + urlPattern: /^https:\/\/cdn\.socket\.io\//, + handler: 'cacheFirst' + }, + { + urlPattern: /\/socket.io\//, + handler: 'cacheFirst' + }, + { + urlPattern: /\/_debugbar\//, + handler: 'cacheFirst' + }, + { + urlPattern: /\/browser-sync\//, + handler: 'cacheFirst' + }, + { + urlPattern: /\/avatar\//, + handler: 'cacheFirst' + } + ], + }) + ] + }); \ No newline at end of file -- cgit v1.2.3