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

Have injectManifest work directly on file #2303

Closed
Snugug opened this issue Dec 10, 2019 · 7 comments
Closed

Have injectManifest work directly on file #2303

Snugug opened this issue Dec 10, 2019 · 7 comments

Comments

@Snugug
Copy link
Contributor

Snugug commented Dec 10, 2019

Welcome! Please use this template for reporting bugs or requesting features. For questions about using Workbox, the best place to ask is Stack Overflow, tagged with [workbox]: https://stackoverflow.com/questions/ask?tags=workbox

Library Affected:
workbox-build

Browser & Platform:
all OSes

Issue or Feature Request Description:
One struggle I'm running into with using Workbox with a JS bundler (in my case Rollup) is that it doesn't play nicely in the JS bundler ecosystem. Specifically, if I want to use injectManifest, I need to give over control over to Workbox instead of working acting as a plugin manipulating the files already being worked on in the bundler. The net result of this is that if I want to use both injectManifest and compile my service worker through a bundler, there's an intermediate step where my compiled SW must be written to disk.

What I'd like to see is the ability for injectManifest to either take in an AST or a string and be able to export either a string or an AST instead of reading and writing files directly, thus allowing bundlers like Rollup and Webpack to have plugins that are able to fully interact with the rest of their ecosystems.

@jeffposnick
Copy link
Contributor

For historical reasons, we maintain a "first-party" webpack plugin, and using InjectManifest in v5 will trigger both a compilation and manifest insertion: #1854

We're not doing the same for Rollup, but someone from the community has created https://www.npmjs.com/package/rollup-plugin-workbox

Using either the webpack or the Rollup plugin is a viable approach for anyone who wants to do both compilation + manifest injection in the same step, and it's now easier to split them in two steps without needing to create a temporary file, following #2231.

So, in general, this should be addressed in v5. Let me know if you feel differently.

@Snugug
Copy link
Contributor Author

Snugug commented Dec 11, 2019

Thanks for the update Jeff. I'd like to reopen this as, currently written, the Rollup Plugin calls injectManifest as exported and, to the best of my reading, the v5 version of injectManifest still reads a file from the filesystem and writes a file back to the filesystem, and doesn't allow for passing in a string.

I think, given the way v5 is built, it's certainly possible to construct a Rollup plugin that would work without reading and writing a file by forking the inject-manifest file and bypassing the file read/write bits. Is that what you'd recommend?

@jeffposnick jeffposnick reopened this Dec 11, 2019
@Snugug
Copy link
Contributor Author

Snugug commented Dec 11, 2019

For a little bit of background into doing this as a Rollup plugin, Rollup can provide both a string and a sourcemap, so I'd love to be able to have injectManifest (or a sibling function) take optionally both in.

@jeffposnick
Copy link
Contributor

If you want to mimic injectManifest while avoiding writing things to disk, using https://github.com/GoogleChrome/workbox/blob/0c4a7346b1c8c414df4cd765a31deede95a0ba63/packages/workbox-build/src/lib/get-file-manifest-entries.js directly would give you that ability.

That should be callable from within a Rollup plugin, and taking that return value and doing a string replacement of self.__WB_MANIFEST with the manifest would accomplish pretty much the same thing as what injectManifest does.

The core Workbox team doesn't have any plans to maintain a Rollup plugin, but perhaps working with the folks behind https://www.npmjs.com/package/rollup-plugin-workbox to add in that functionality would make sense?

@Snugug
Copy link
Contributor Author

Snugug commented Dec 11, 2019

Makes sense to me. That's basically what I'm prototyping right now.

@karabaesh
Copy link

@Snugug I am working on the same problem right now. Do you have already any solution that you can share with us?

@Snugug
Copy link
Contributor Author

Snugug commented Jan 23, 2020 via email

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

No branches or pull requests

3 participants