Welcome to 16892 Developer Community-Open, Learning,Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am trying to make my laravel a PWA. What I did is, run

npm install workbox-cli -g

create sw-base.js file in public folder,

importScripts(
    'https://storage.googleapis.com/workbox-cdn/releases/6.0.2/workbox-sw.js'
);

workbox.precaching.precacheAndRoute([]);

Now created a workbox-config.js file at the root folder,

module.exports = {
    globDirectory: 'public/',
    globPatterns: ['**/*.{js,css,png,jpg}','offline.html'],
    swSrc: 'public/sw-base.js',
    swDest: 'public/service-worker.js',
    globIgnores: [
        '../workbox-cli-config.js',
        'photos/**'
  ]
};

added scripts in package.json

"generate-sw": "workbox injectManifest workbox-config.js"

Now When running

npm run generate-sw

I get error like

Service worker generation failed: Unable to find a place to inject the manifest. Please ensure that your service worker file contains the following: self.__WB_MANIFEST

I followed this tutorial, but not working.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
822 views
Welcome To Ask or Share your Answers For Others

1 Answer

If you want to use InjectManifest you should have an existing service worker. I would reccomend use GenerateSW. It will create the service worker for you.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to 16892 Developer Community-Open, Learning and Share
...