GoogleChromeLabs / sw-precache

[Deprecated] A node module to generate service worker code that will precache specific resources so they work offline.
https://developers.google.com/web/tools/workbox/guides/migrations/migrate-from-sw
Apache License 2.0
5.23k stars 389 forks source link

sw-precache freezes on vueJS build #379

Open NickHatBoecker opened 5 years ago

NickHatBoecker commented 5 years ago

Hey guys,

I have a problem since I installed sw-precache for my vueJS application. When running npm run serve (alias for vue-cli-service serve) it tries to start the dev server but then freezes with 98% after emitting swPrecacheTotal precache size is about 12.5 kB for 4 resources.

It always freezes at 98% and this happens on every try. When I remove sw-precache everything is working. Any ideas?

vue.config.js:

const SWPrecache = require('sw-precache-webpack-plugin')

module.exports = {
    configureWebpack: {
        plugins: [
            new SWPrecache({
                cacheId: 'nhb-year-in-pixels',
                filepath: 'dist/service-worker.js',
                staticFileGlobs: [
                    'dist/*',
                    'dist/**/*',
                ],
                stripPrefix: 'dist/',
                maximumFileSizeToCacheInBytes: 3097152,
            })
        ],
    }
}

Thanks in advance!

NickHatBoecker commented 5 years ago

Fixed this with the following condition:

const SWPrecache = require('sw-precache-webpack-plugin')

module.exports = {
    configureWebpack: config => {
        if (process.env.NODE_ENV === 'production') {
            config.plugins.push(
                new SWPrecache({
                    cacheId: 'nhb-year-in-pixels',
                    filepath: 'dist/service-worker.js',
                    staticFileGlobs: [
                        'dist/*',
                        'dist/**/*',
                    ],
                    stripPrefix: 'dist/',
                    maximumFileSizeToCacheInBytes: 3097152,
                })
            )
        }
    },
}