Provide a webpack plugin [feature request]
lassombra opened this issue · 3 comments
It would be really nice if this tool would be available as a webpack plugin as well.
Graphql-tag has a loader module that it offers which I use extensively. I would love to have as an automatic part of my build a similar function with persisted queries.
I have a couple of theories about how this might function, they start out pretty much the same.
- Similar to extract text plugin with remove:false, offers a loader which is functionally a "pass through" but stores the results of previous loaders to use in the plugin
- Plugin emits a persisted query json that is parallel to emitted bundles. Plugin is aware of multiple bundles (through compiler information) to ensure that parallel ones have different ids.
Option 1 ends here. Option 2 goes one step further and does something like DefinePlugin to replace some kind of defined import with a json loader which has the json inlined.
@lassombra I have put together alpha version of PersistGraphQL Webpack Plugin, which addresses both of described options, I believe. The plugin is here and available on npm:
https://github.com/sysgears/persistgraphql-webpack-plugin
The example of using this plugin with project that utilizes Webpack both for backend and frontend is here:
sysgears/apollo-universal-starter-kit@5a553fe
That looks like exactly what I was hoping for. I'll try it out sometime next week, thanks.
For full example of adding persisted queries via PersistGraphQL Webpack Plugin please see commit:
sysgears/apollo-universal-starter-kit@dfd6e4e