-
Notifications
You must be signed in to change notification settings - Fork 832
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
Webpack Discussion #696
Comments
@goldhand sounds good to me, do you have a list of things that aren't currently supported? Would help me get a feel for what is missing in |
Any sw-precache-webpack-plugin options that were added to support sw-precacheThese are found under the plugin options: section of the sw-precache-webpack-plugin configuration docs. I think workbox-build covers:
which only leaves Any default behaviors that sw-precache-webpack-plugin is passing to sw-precache.I think we should try to provide the same default behavior mapped to the workbox equivalent, if possible. These are found under the sw-precache options: section of the sw-precache-webpack-plugin configuration docs. I need to look more into it but my connection is pretty spotty at the moment (sw cache use case 😆) but it looks like currently there is:
That provide default options for workbox-build. I don't think all the functionality is the same but I looks like some are covered. A couple missing options that are awesome IMHO are:
Any options that sw-precache provided but workbox-webpack-plugin (through workbox-build) does not.It looks like sw-lib can support the Others? |
I would like to be able to add other features (like runtime caching) via workbox-webpack-plugin or have a clear documentation how to do it otherwise (sorry if the documentation is available but I've missed it). What is unclear to me is that:
This very same question could also be laid out differently:
If I make an SW script by hand and configure my desired runtime caching, broadcast channel and whatnot, how can I leverage the static file glob listing for precaching in the very same script using the webpack plugin? |
Re: a couple of separate comments:
+1. This is what I'd expect from a Webpack solution, since Webpack already knows everything it needs to get this right. The
So I think that this is one big difference between what you could do with
|
Random feature idea: it would be super awesome if we could specify chunks to use for precaching like is possible with html-webpack-plugin (but for adding chunks to bundles): module.exports = {
...
entry: {
appshell: [
'babel-polyfill',
'src/appshell',
],
},
plugins: [
WorkboxPlugin({
...
chunks: ['appshell'],
}),
],
}; If the webpack plugin can move away from using glob (and leverage the emitted webpack assets instead) I think this can possibly replace note: by default just cache all the chunks like html-webpack-plugin and sw-precache-webpack-plugin already do |
@jeffposnick it sounds like we don't need |
For better or worse, there are two "modes" supported by
The |
@anilanar work in #724 addresses some issues with the current webpack plugin interface and prototypes a possible solution to these issues. Issues that were mentioned in this pr:
The proposed solution is to break the webpack plugin into multiple, feature-specific, plugins. What are the pros and cons of this api? Are there other apis that can solve the mentioned issues while minimizing complexity for developers seeking webpack + workbox integration? |
I'd also like to make the following points: Regarding
Regarding service worker in projects bundled with webpack
Regarding separation of webpack plugin into separate plugins
In regards to making workbox easy to use
TBH, this is all too complicated in part due to how webpack works and how SW makes some things harder. Nonetheless, I can't think of a quick solution. The problem itself is hard and the solution would involve a combination of many small solutions all around. BTW I have a quick implementation for |
I'll apologize for being late to this issue with input.
I agree with your earlier suggestions, @goldhand. Support for Minification is an interesting one. From a purist perspective, I wish we could defer this to the user to decide how best to proceed, but I've seen enough Webpack configs where folks forget (or aren't aware) they need to do extra steps to minify that I think taking care of
+1. This will be particularly important for our migration story.
I'll echo Jeff's support for something like this. Hopefully
Having had to deal with the pains of wiring things up manually to I'll comment on @anilanar's latest in just a sec separately. |
Thanks for all of your input, @anilanar!
I can see where @mikefowler on another thread suggested specifying a regex so you can control where in the
Do you have an example of a Webpack plugin that's been shifting in that direction? This would be useful for reference. Perhaps the first that comes to mind is
This is all valuable feedback. As you've acknowledged, we're dealing with an API surrounded with inherent complexity, an immense amount of nuance and lots of foot-guns. Some of this pain, |
One more observation I made today in our project:
Solution:
Are there some use cases where you would like to inject it at a specific location? Prepending it would allow you to use the manifest throughout the service worker. We do something similar in webpack by splitting and prepending runtime/chunk manifest to help achieve long-term hash stability. e.g.
I don't have one off top of my head. It may be a misconception I wanted to believe in. I think community is ready for it; nevertheless it is not important. Even if there is merit to splitting plugins, its benefit is insignificant right now. |
@anilanar thank you for all your input.
This is a very valid point. We need the emitted assets to exist before we can generate the manifest, then we need to go in and modify one of these assets using that information. It's a difficult problem. Is there another way of approaching this? I think you suggest that
This is my understanding too but I think we need to come up with an approach that works with a single compilation. We just can't make running webpack twice a requirement in order to support workbox.
Service workers are extremely powerful and potential dangerous if not used correctly but I don't think that's a reason to make this api difficult to use.
This can be fixed if we use the emitted asset paths from webpack rather than glob patterns when we create the manifest (what sw-precache-webpack-plugin does currently). |
@addyosmani regarding minification: when we generate a service worker, this happens after the webpack compilation, where most people would include their minify / uglify processes (through webpack plugins). The generated service worker asset is not piped through webpack's plugins and can't be minified / uglified using webpack plugins |
I'm pretty much pro everything @goldhand is suggesting and I know it will be a drastic change from where we are today. Sadly, I'm lacking the WebPack knowledge to really comment more than I like what I'm reading. All I can say is - if you can start creating PR's against the v3 branch for the WebPack plugin, raise issues if you when you hit more specific areas where you'd like to discuss API's approaches, I think we can start moving forward. I'm generally of the opinion that the injectManifest isn't right call for webpack because it has so much more context. I think the most immediate decision is how does a developer indicate they want to generate a service worker vs add a manifest to an existing service worker (Which can be done via inlining, injecting or importing - what ever is best for WebPack). Any suggestions? Regarding API / Option names - Please do keep the current options from current precache plugin to ease transitioning, but would be good to have the option to rename options if there is a better name an then just link up to old values (We are currently doing this with workbox-build at the moment in a few places). |
@gauntface One thing that has been difficult is the pattern where you |
We have landed and continue to land changes on the webpack plugin thanks to @goldhand's awesome work. There are a number of smaller issues opened and a number of TODO's in code that should cover the issues raised in this monster thread so I'm going to close this for now. If there are outstanding issues or topics to discuss please open issues :) <3 to @goldhand for all of this. |
Library Affected:
workbox-webpack-plugin
I wanted to discuss the idea of supporting the same configuration from sw-precache-webpack-plugin inside workbox-webpack-plugin.
I think it would make it easier for users of sw-precache-webpack-plugin to transition to using workbox-webpack-plugin if they are able to use the same configuration with workbox-webpack-plugin.
I also wanted to consolidate a list of any other feature suggestions that might help the workbox / webpack integration feel seamless.
A few I'd like to see are:
There's also a lot of requests for webpack-dev-middleware/dev-server support as seen in #577 and goldhand/sw-precache-webpack-plugin#17
The text was updated successfully, but these errors were encountered: