shellscape / webpack-plugin-serve

A Development Server in a Webpack Plugin
http://shellscape.org
Mozilla Public License 2.0
337 stars 53 forks source link

vote: lazy compilation mode #150

Open notiv-nt opened 5 years ago

notiv-nt commented 5 years ago

Please vote for this feature by using the Github Reactions button and the πŸ‘ reaction. When this feature reaches 120 votes, it will be reconsidered.


Feature Use Case

Compile only on first request, needed when the client part is divided into separate modules (microfrontends?) is it even possible?

Feature Proposal

The same as https://webpack.js.org/configuration/dev-server/#devserverlazy-

Reason

It takes up too much RAM

shellscape commented 5 years ago

Thanks for opening an issue. webpack-plugin-serve doesn't store the compiled output in memory (by default). For clarification, are you stating that the webpack process itself is using too much memory while compiling all of the bundles for your app?

notiv-nt commented 5 years ago

@shellscape for now, dev-server with lazy takes ~800mb, this plugin ~1100mb

shellscape commented 5 years ago

A few more questions so we can get on the same page for this request:

Which webpack CLI are you using to run the webpack build with this plugin?

(If not already using it) If you try webpack-nano does the memory usage fall?

What are the compiled bundle sizes?

About how many files make up each bundle?

shellscape commented 5 years ago

@bebraw @PlayMa256 are either of you aware of a means to cancel a compilation within a hook (or any other means)? The problem we've got with this request is that WDM runs it's own compiler and uses chokidar to watch the files for a compiler, rather than using webpack's internal watcher. It can start and stop compilations that way. That's not something we want to do here - the complication of juggling that would mean we adopt the same disadvantages as WDM.

matheus1lva commented 5 years ago

No @shellscape There was an open issue on webpack that was requesting the same feature and another one trying to abort during watch mode

Accordingly to Tobias, adding an abort o watch mode is not easy to implement and they don’t have any ideas/solutions for that

And also there is something that nuxt implements that sort of cancels the compilation... I was not able to locate which part of the code does that.

shellscape commented 5 years ago

For Nuxt I think it was just that multiple file changes were causing multiple compiles so they implemented a debounce of some kind. But I could be wrong about that.

I was also looking to see if there was some way to delay one of the compilers in a multicompiler.

https://github.com/MattDiMu/webpack-delay-plugin/blob/master/index.js We might be able to use this approach in conjunction with koa-router internally, like using a Promise instead of a timeout. Or use a timeout and clear it.

shellscape commented 5 years ago

I've spent a bunch of time looking into how to best implement this. I managed to get a working example of how this would go, and it's not rocket science by any means. Here are the basic component parts:

It works, but it jacks up the flow of code quite a bit, and it's a fair bit of extra code we'd have to add.

All that said, I'm not opposed to adding this, but we're going to have to get a pretty good response from the userbase to make all of that happen. I'm going to turn this into a voting feature issue and set the threshold at 120 πŸ‘ - or about 2% of the userbase.