-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
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
add experimental lazy compilation #12469
Conversation
For maintainers only:
|
const logger = compiler.getInfrastructureLogger("LazyCompilationBackend"); | ||
const activeModules = new Map(); | ||
const prefix = "/lazy-compilation-using-"; | ||
const server = http.createServer((req, res) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about https
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would require providing a cert and key. We can definitely add that before this leaves experimental status.
5d57cd9
to
b41217b
Compare
b41217b
to
a1515fa
Compare
I am so happy that webpack will integrate this feature into its core. 🎉 🎉 🎉 |
Thank you for your pull request! The most important CI builds succeeded, we’ll review the pull request soon. |
I've created an issue to document this in webpack/webpack.js.org. |
it's so cooooool! |
Great that you like it. Could you provide more feedback/details? |
Sure! i will test it in weekend and give some feedback. |
Enabling this feature seems to cause our (very large) build to take longer, reload times on a small react component seem unchanged. The app has many (hundreds) of dynamic import chunks. Let me know if I can provide any other info. Relevant dependencies:
Before
After
|
|
This adds an experimental feature which allows to compile only the part of the application which is currently in use. Additional
import()
s and entrypoints which are currently not in use do not affect compilation performance when this feature is enabled.When used webpack opens an additional communication channel between client and compiler via Server-Send-Events. With this channel the currently used
import()
s are told the compiler. The compiler will include theseimport()
s resp. entrypoints in the next compilation. When in watch mode and newimport()
s/entrypoints are communicated to the compiler, it will automatically recompile.When Hot Module Replacement is not enabled, (manual) refresh of the page is required.
This also works when targeting node.js. Including HMR in node.js.
After 2 minutes not using a
import()
resp. entrypoint it be garbage collected. Once compiled modules will stay in cache, so compiling it again is probably pretty fast. It's recommended to combine this with the Persistent Cache to keep the cache even after restarting.For logging use
infrastructureLogging.debug: /LazyCompilationBackend/
.What kind of change does this PR introduce?
feature
Did you add tests for your changes?
yes, but that could be improved.
Does this PR introduce a breaking change?
no
What needs to be documented once your changes are merged?
experiments.lazyCompilation
: Compilesimport()
only when requested using HMR.experiments.lazyCompilation.client
: Allows to use a custom client. It need to expose a single export namedkeepAlive
which is a({ data: any, active: boolean, module: Module, onError: (err: Error) => void }) => () => void
. It's returning a dispose function. As defaultwebpack/hot/lazy-compilation-{node|web}.js
is used.require("webpack/hot/lazy-compilation-web.js" + __resourceQuery)
and call thekeepAlive
method from your own implementation.experiments.lazyCompilation.backend
: Allows to use a custom backend.(compiler: Compiler, client: string) => Promise<Backend>
(Promise or node-style callback)Backend = { dispose: (callback) => void, module: (module: WebpackModule) => { client: string, data: any, active: boolean } }
data
is a url encoded key for the module.urlPrefix + keys.join("@")
should be used to access the EventSource.Prior art
cc @liximomo