Skip to content
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

Entry template with production build #8

Open
PeterKottas opened this issue Apr 6, 2022 · 3 comments
Open

Entry template with production build #8

PeterKottas opened this issue Apr 6, 2022 · 3 comments

Comments

@PeterKottas
Copy link

Guys, thanks for rescuing this useful package! There is however one serious issue. I actually wonder how am I the only one seeing this?!

When you use an entry template, in development mode, all works as expected, however, once you switch to production mode in webpack, all hell breaks loose. Apparently, it somehow removes all callbacks from listeners. I've never seen anything like this before, but that seems to be the case.

I've made a minimal repo: https://github.com/PeterKottas/offline-plugin-webpack-5

Long story short, my template is this:

const constFunction = () => {
  console.log("constFunction");
};
self.addEventListener("push", constFunction);
self.addEventListener("notificationclick", () => {
  console.log("inlineFunction");
});
self.addEventListener("message", function () {
  console.log("function");
});

But when compiled in production mode, the above becomes:

// Code omitted
self.addEventListener("push", () => {}),
self.addEventListener("notificationclick", () => {}),
self.addEventListener("message", function () {});
// Code omitted

Please try for yourself, simply run "npm run build-dev", confirm that the code ends up in the final sw.js, then run "npm run build-prod" and you will see that the callbacks are stripped away. Any ideas? Thanks

@PeterKottas
Copy link
Author

I do feel like this has something to do with this file: https://github.com/LeComptoirDesPharmacies/offline-plugin/blob/master/src/misc/get-minification-plugin.js
There's some weird logic regarding minification that might be outdated. I will continue looking

@PeterKottas
Copy link
Author

So apparently the problem is https://github.com/LeComptoirDesPharmacies/offline-plugin/blob/master/src/service-worker.js#L75. Due to the way the loader is coded, drop_console will apparently remove callback functions. Fixed by #9 . I would greatly appreciate if you could take a look and merge if everything makes sense. Many thanks!

@PeterKottas
Copy link
Author

I don't have a good feeling ... seems like forked died as well. Is this lib cursed or what :D Well anyways, I will remain hopeful you will reply. If not, I'll just release this under our handle.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant