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

vote: lazy compilation mode #150

Open
notiv-nt opened this issue Aug 2, 2019 · 7 comments
Open

vote: lazy compilation mode #150

notiv-nt opened this issue Aug 2, 2019 · 7 comments

Comments

@notiv-nt
Copy link

notiv-nt commented Aug 2, 2019

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
Copy link
Owner

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
Copy link
Author

notiv-nt commented Aug 2, 2019

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

@shellscape
Copy link
Owner

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
Copy link
Owner

@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
Copy link
Collaborator

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
Copy link
Owner

shellscape commented Aug 3, 2019

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
Copy link
Owner

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:

  • Add an option to start the server immediately, instead of waiting for the compiler to finish
  • Create a deferred promise that is resolved within custom middleware (app.use ...) if the requested file path matches the output file target
  • Add a custom plugin for compiler.plugin('watch-run') which invokes the cb parameter when the deferred promise resolves

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.

@shellscape shellscape changed the title Lazy mode vote: lazy compilation mode Sep 16, 2019
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