-
Notifications
You must be signed in to change notification settings - Fork 104
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 dev server support? #17
Comments
@oliviertassinari I think the issue is that webpack-dev-server serves bundles from memory. This plugin saves a service worker to your build directory. It isn't an input asset for webpack so the service worker isn't bundled or anything (intentionally but there could be other approaches). |
Thanks, so I feel like I'm going in the right direction. I will try to work on it next weekend. |
Thanks @oliviertassinari let me know how it goes or if you have any more questions 😄 |
@oliviertassinari any luck so far? |
I haven't found time to work on it yet. I'm delaying every week, it's a shame 😁 . |
@oliviertassinari any chance you could share whatever progress or ideas you have on making this work? I'd really like to get this working for electrode-io/electrode#40 and am happy to put in the work on it. |
@aweary The most challenging part of building serviceworker-webpack-plugin was integrating with the webpack plugin API so that it's serving the Here is what I have in mind:
|
Right, I though I could have bypassed this limitation with the generated API, but no. I'm closing this issue. I'm gonna use the I couldn't go further than: import swPrecache from 'sw-precache';
// ...
new ServiceWorkerWebpackPlugin({
entry: path.join(__dirname, 'src/sw.js'),
excludes: [
'**/.*',
'**/*.map',
'*.html',
],
publicPath: `${__dirname}/`,
template: (serviceWorkerOption) => {
return swPrecache.generate({
staticFileGlobs: serviceWorkerOption.assets,
});
},
}), |
Any solution? I'm working in a project which uses webpack-dev-middleware so de bundle.js and style.css files and generated on the fly while developing and only are created witin the The problem, as you comment, is if I specify the
The files are not included in the service-worker code because they really not exists and are generated on the fly by webpack-dev-middleware. Is there a way to bypass that limitiation and always include the specified files in the service-worker code? Is it possible and easy to add that options? Thanks |
@acanimal not yet. I will reopen the issue though since there seems to be some demand for this feature. |
Thanks. I follow the code and seems all the values specified in the |
Tip: use the |
Does anyone have an example of using @phun-ky suggested |
@phun-ky @goldhand @f If I get this right, if I run both this plugin with write-file-webpack-plugin, my "sw.js" is gonna be forced to written to the file system, and if running with the dev-server/node the filesystem would be memory so webpack-dev-server could catch up? new WriteFilePlugin({
// Write only files that have "sw.js" extension.
test: /\sw.js$/,
useHashIndex: true
}) |
@goldhand I am pretty young and dumb about webpack in general, but the actual file write operation on ly happens here. |
Problem here is that this plugin uses separate tool ( |
@ragingwind released https://github.com/ragingwind/sw-precache-webpack-dev-plugin recently. I can't personally vouch for it, and I've never seen the need to have |
@jeffposnick yeah, I thought about it as rare case too, but some people need to test locally push notifications or other SW features, so they use it. But that's still rare case, most often they just do it even though their envs becomes unusable after that. General suggestion: if you don't use push/sync/etc events in your SW -- just disable it in dev and check "if it's still working" on a separate server (e.g. |
That's what I'd kind of think would be ideal for a local developer environment. |
@cescoferraro, your thoughts are correct, that is the summary of the problem. I don't know how young you are but you're not dumb. I want to test @ragingwind solution for webpack-dev-server, if that works, I will use it to add webpack-dev-server support to this plugin. As @jeffposnick mentioned, I also typically do not want super strong caching strategies implemented while I'm developing but there is no question that there is a strong demand for this feature. |
Looks like using the compiler option, as @cescoferraro mentioned, will solve this. See this solution |
First of all, It has a very limited case of using. The reason why I made up another plugin for However, A few of people, get started with SW recently, who around me would like to test, debug and watch what's going on service worker in local because they wanted to change configurations frequently while they were developing. So, it was released as another plugin named +dev with a limited purpose. Secondly, that plugin doesn't use officially exported APIs from sw-precahse, Using indirection of way for hashing and listing file's path If I would thought that It's a very useful feature for most of case and built in strong, I will make a new PR. |
@ragingwind I would love to see a pr for this feature. This is the longest running thread/issue with this plugin. I like your dev plugin but I feel that adding a dev configuration flag to this plugin so users can easily opt in to dev support would be really convenient. |
I'm really missing this right now. 👍 |
Unfortunately, there is no way for sw-precache to work with webpack-dev-server. sw-precache uses paths on the file system to generate the service worker. They don't exist on the file system so this will not be possible. |
@goldhand I'm sorry for receiving no answer from me. Meanwhile, I was looking for another way to make it to support working on webpack-dev-server for a new PR. However, It reached that there is no way for working on web-deb-server unless and until sw-precache supports various files-system, as you mentioned in readme. So, I wouldn't make a PR with vary unstable and workaround code. |
Reading the README of the project you say that webpack dev server is not supported. I may be able to help.
But first I need to understand, what the limitations are about?
We could extend the API of serviceworker-webpack-plugin to accept a generated service worker string.
The text was updated successfully, but these errors were encountered: