-
Notifications
You must be signed in to change notification settings - Fork 827
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[workbox-webpack-plugin] v3 Entries array passed to manifestTransforms is empty #1227
Comments
My hunch is that your config is using chunks from webpack rather than globbing for any files from disk and it's only the globbed files that would appear in the manifestTransform. @jeffposnick is this a case of docs needing updating? |
@gauntface is correct. I should be able to add in a new This is covered by https://developers.google.com/web/tools/workbox/modules/workbox-webpack-plugin by virtue of @akash5474 if you have any feedback about improving the way that's documented (once you've had a look through that page), we're happy to reconsider. |
...and just to explore some alternative approaches before we lock down the v3 interface:
What's your use case for wanting to transform the precache manifest generated from the webpack assets, by the way? That might help inform the best path forward. |
@jeffposnick Thanks for the response and fixing the other issue I opened. I did overlook the "These options configure behavior unrelated to the webpack compilation." text, completely my fault. A build time error would definitely be helpful. Adding a gap between the tables might improve the visibility, I kind of scrolled past the row with that message without noticing (entirely my fault). Maybe adding a subsection in the right side menu underneath "GenerateSW Plugin" and "InjectManifest Plugin", though I don't know if that's a good solution. Not sure my use case warrants changing the behavior of I'm building a single page app and was trying to use a transform to change the url for my html file (generated by html-webpack-plugin) from something like I want the revision for the precache-manifest entry corresponding to the html file (generated by html-webpack-plugin) to apply to the markup that I actually serve which is generated server-side (essentially the same html with some additional headers depending on the page and some other variables). Based on available options, I think the correct configuration for my case (singlepage app and generating The server-side files will change much less often. I can't use a string and it would be difficult to use an array of glob patterns, I believe the pattern(s) would have to cover my entire app (and what if I update a dependency and my vendor file's hash changes?). My config currently looks something like this: module.exports = {
entry: './src/index.js',
output: {
path: path.resolve(__dirname, 'dist/static/app'),
publicPath: '/static/app/',
filename: 'js/[name].js',
},
plugins: [
new WorkboxPlugin.GenerateSW({
swDest: '../../service-worker.js',
navigateFallback: '/',
templatedUrls: {
'/': 'some-value'
}
})
]
}; Am I correct in thinking that the proper configuration for a single page app includes having both I've played around with different permutations of options and noticed if I don't have both of those, when I refresh the page after the service worker is registered I get a grey screen (see image below) even while online. I can only reload my app by clearing the service worker. This seems like it might be the correct behavior if |
@akash5474 can you share what the set up on your project is, what the desirable manifest should be and what the actual manifest is. At the moment I'm struggling to follow what is going wrong / options to fix it. |
Whatever URL you use for If you're precaching your app shell via the URL |
@gauntface, I think @jeffposnick is on the right track to understanding my initial problem which led to me trying to use the A better way to describe what I'm trying to accomplish might be that I'm generating part of the app shell server side. For example I may add some items to
I did try this but it caches the module.exports = {
entry: './index.js',
output: {
path: path.resolve(__dirname, 'dist/static/app'),
publicPath: '/static/app/',
filename: 'js/[name].[hash].js',
},
plugins: [
new HtmlWebpackPlugin({
template: './index.template.html'
}),
new WorkboxPlugin.GenerateSW({
swDest: '../../service-worker.js',
navigateFallback: '/static/app/index.html',
}),
]
} And when using the new WorkboxPlugin.GenerateSW({
swDest: '../../service-worker.js',
navigateFallback: '/',
templatedUrls: {
'/': ['./server.js']
}
}), |
Is '/' made up of templates available in your webpack config? Or are these files only on the server. |
I don't think you can use precaching for your HTML in that case. If you need to serve HTML that varies depending on some characteristic of the client's request headers, that's not nuance that you'd be able to represent with precaching. You could use runtime caching instead, potentially with a stale-while-revalidate policy, and get some of the same benefits of taking network delays out of the rendering critical path after your initial navigation. |
You can also just add a server side generated manifest: importScripts('/server-side-manifest.js');
workbox.precaching.precache(self.__serverSideManifest); Then you would have a service side endpoint that would respond to self.__serverSideManifest = [
{
url: "/",
revision: "........................"
}
]; You would need to create a revision that is a hash of the contents of '/' (i.e. if you change the output of '/' the revision value changes too). |
importScripts('/server-side-manifest.js'); won't work, because precaching relies on there being a change to the top-level service worker file in order to trigger a new (The webpack plugin, which also relies on an external manifest, automatically inserts a statement into the top-level service worker that looks like importScripts('/precache-manifest.[hash].js'); That |
@jeffposnick you are right is would need to be: importScripts('/server-side-manifest.<revision>.js'); |
How do you feel about supporting the Instead of utilizing globbing, perhaps we can support looking into |
@raejin I can picture a scenario where that would be useful, not sure what the config options of that would look like however (and I'm a newb at Webpack). Could you open an issue with a proposal of a config that you think would fit this use case? |
It would be nice if For example the generated manifest would have I think there would be an use-case for the before mentioned I could go around this by using workbox-build through a node script that is run after webpack build, but it would be nice to do this directly in the build step :) |
ditto to @ottoo's suggestion. |
Any updates regarding this? Would love to see |
It's high on our list of planned changes for the The master tracking list for those updates is #1591 |
'cause the `Workbox` webpack plugin won't let you manually override paths to precached assets generated by webpack, per GoogleChrome/workbox#1227 (comment).
Hi @jeffposnick @gauntface.. I'm using client/build
├── bundles
│ └── pages
│ ├── _app.js
│ ├── _document.js
│ ├── _error.js
│ ├── index.js
├── chunks
│ ├── lazysizes_c7d1c726a13ef0281040919ab87052dd.js
├── precache-manifest.ea29d9a87efea6a22b482d6f07e9c0a8.js
├── static
│ ├── commons
│ │ ├── main.js
│ │ ├── manifest.js
│ ├── style.css
└── sw.js Accordingly, the generated self.__precacheManifest = [
{
"revision": "e17045946da6be83b2c8",
"url": "bundles/pages/_app.js"
},
{
"revision": "aafdbc9341182f758412",
"url": "static/commons/main.js"
},
{
"revision": "aafdbc9341182f758412",
"url": "static/style.css"
},
{
"revision": "01816bc9594df2c83999",
"url": "static/commons/manifest.js"
},
{
"revision": "7c5946399b2b21a5fc74",
"url": "chunks/lazysizes_c7d1c726a13ef0281040919ab87052dd.js"
},
{
"revision": "1e6a77ee5a8e6129f447",
"url": "bundles/pages/index.js"
},
{
"revision": "290487a965ccea8a6925",
"url": "bundles/pages/_error.js"
},
{
"revision": "e92680204ba0d06de76c",
"url": "bundles/pages/_document.js"
},
]; But Next.js serves above assets to very different paths, and so I need to transfrom the above manifest URLs to match the paths at which they are getting served by Next.js For reference Next.js serves the emitted assets according to below sort of would-be modifyUrlPrefix : {
'bundles/pages/' : `/_next/${nextBuildId}/page/`,
'chunks/' : '/_next/webpack/chunks/',
'static/' : '/_next/static/',
}, My options currently AFAIK:
Kindly suggest how would you guys go about this problem! |
Hi. So I had to write a custom webpack plugin - very much similar to that used in next-offline |
Guys sorry but I'm running into an issue with document (HTML) (pre)cache updation using Next. |
Both |
This should be addressed by the current Workbox v5.0.0 alpha. |
Library Affected:
workbox-webpack-plugin@3.0.0-alpha.6
Browser & Platform:
node v8.9.1, npm v5.5.1, Mac OSX 10.13.2
Issue or Feature Request Description:
Title describes the issue, the manifestEntries array passed as an argument into manifestTransform functions is empty.
I've created a repo to illustrate the problem. Here's a link to the branch with a minimal example reproducing the issue:
https://github.com/akash5474/workbox_ex/tree/manifestTransforms
The text was updated successfully, but these errors were encountered: