rmarscher / virtual-module-webpack-plugin

Adds the contents of a virtual file to webpack's cached file system without writing it to disk
174 stars 17 forks source link

Add support for declaring 'contents' as a promise (or a function returning a promise) #11

Closed papandreou closed 7 years ago

papandreou commented 7 years ago

Just something I hacked up as part of another experiment -- contributing/sharing it here in case it might be useful.

rmarscher commented 7 years ago

Thanks for the pull request @papandreou. The ability to pull the contents async from a promise sounds useful. If the promise took a long time to resolve, I think there could be a race condition where the webpack compilation starts before the resolve plugin has been attached to the compiler. But I think those resolve plugins might work via async so inside the resolverPlugin, it could detect if the contents are a promise and resolve it before populating the virtual filesystem and calling the plugin callback.

This pull also seems to be causing one of the tests to fail. I'll ping you when I've pushed something up that does what I outlined above and maybe you can test if it works with your experiment. Might be a little bit before I get to it though.

papandreou commented 7 years ago

Oh, I didn't realize there was a test suite -- sorry! I fixed the bug and force pushed now :)

papandreou commented 7 years ago

Sorry, apparently I attempted to push to the wrong remote repo, which failed without me noticing. Redid the fix and pushed now.

papandreou commented 7 years ago

Played around with it a bit more, but I don't think it'll work. As far as I can tell, it's not enough to have the contents injected by the time the resolver plugin calls its callback. That's probably what you tried to point out in your initial feedback.

papandreou commented 7 years ago

Let's close this PR until new insight comes up.

rmarscher commented 7 years ago

@papandreou Thanks for digging into it more. I'll let you know if I find a way it could work.