Bundling workbox via webpack
See original GitHub issueLibrary Affected: workbox-build
Browser & Platform: Google Chrome v77 on Windows 10.
I’m using create-react-app 3.2.0 (which bundles webpack 4.41.0).
Up to this point I’ve been pull workbox from the Google CDN using importScripts()
. However, this is no use when my PWA is offline. I’d like to bundle workbox using webpack. I’ve worked through your docs but can’t see where I’m supposed to import workbox modules (import isn’t supported in a service worker?).
https://developers.google.com/web/tools/workbox/guides/using-bundlers
However, these import statements run in Service Worker scope?
I’m using workbox-build
and placing the import ... from
statements in my template.js
.
My build.js
:
const workbox = require("workbox-build");
workbox.injectManifest({
swSrc: "src/ServiceWorker/template.js",
swDest: "build/sw.js",
globDirectory: "build",
globPatterns: [
"**\/*.{css,html,ico,png,svg,xml}",
"static\/**\/*.chunk.{js,css}",
"static\/js\/*.js"
]
}).then(({ count, size, warnings }) => {
warnings.forEach(console.warn);
console.log(
`${count} files will be precached (${Math.floor(size / 1024)} KB)`
);
});
Where am I supposed to import functions from workbox-*
packages?
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
Build A PWA With Webpack And Workbox - Smashing Magazine
This tutorial will help you transform an app that doesn't work offline into a PWA that works offline and shows an update available...
Read more >workbox-webpack-plugin - Chrome Developers
Generate a service worker or inject a precache manifest, using the webpack build tool.
Read more >Create a service worker with Workbox, Webpack and TypeScript
Create a service worker with Workbox, Webpack and TypeScript ... that contains a list of the entry points/generated files of the Webpack bundling...
Read more >Progressive Web Application - webpack
We'll achieve this using a Google project called Workbox which provides ... Asset Size Chunks Chunk Names app.bundle.js 545 kB 0, 1 [emitted]...
Read more >How to use the workbox-webpack-plugin.GenerateSW ... - Snyk
return { files: manifestFiles, }; }, }), // Moment.js is an extremely popular library that bundles large locale files // by default due...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Ok, thanks a ton @jeffposnick. I was making my life harder than needs be.
Here’s what I did to fix this:
Time to enjoy some more TypeScript goodness 😉
@jeffposnick Sorry for asking here but can you please guide me on what should I do: I am currently using workbox CDN for my sw.js But now I want to move away from CDN, the project also uses webpack but when I try to use the workbox-webpack plugin it works but the generated file static/build/sw.js contain 10248 lines of code so is it normal? or I am missing something. And How can I only precache few selected files and not precache any files generated by webpack? webpack.config.js