The content of this section is derived from the content of the following links and is subject to the CC BY 4.0 license.
The following contents can be assumed to be the result of modifications and deletions based on the original contents if not specifically stated.
Lazy Compilation is an optimization technique that delays the compilation of modules until they are actually requested. Modules are only built when they are actually accessed.
Enable lazy compilation, which can greatly improve the dev startup performance of multi-page applications (MPA) or large single-page applications (SPA).
boolean | LazyCompilationOptions
false
Check out the guide for a quick start.
If you have twenty entry points, only the accessed entry points will be built when you enable lazyCompilation. Or if there are many import()
statements in the project, each module pointed to by import()
will only be built when it is actually accessed.
If set to true, lazy compilation will be applied by default to both entry modules and modules pointed to by import()
. You can decide whether it applies only to entries or only to import()
through a configuration object. The entries
option determines whether it applies to entries, while the import()
option determines whether it applies to import()
.
In addition, you can also configure a test
parameter for more fine-grained control over which modules are lazily compiled. The test
parameter can be a regular expression that matches only those modules that should be lazily compiled. It can also be a function where the input is of type 'Module' and returns a boolean value indicating whether it meets the criteria for lazy compilation logic.
string
The path to a custom runtime code that overrides the default lazy compilation client. If you want to customize the logic of the client runtime, you can specify it through this option.
string
Tells the client the server path that needs to be requested. By default it is empty, in a browser environment it will find the server path where the page is located, but in a node environment you need to explicitly specify a specific path.
string
'/lazy-compilation-using-'
Customize the prefix used for lazy compilation endpoint. By default, the lazy compilation middleware uses the /lazy-compilation-using-
prefix for handling requests.
If you do not use Rspack's own dev server and instead use your own server as the dev server, you generally need to add another client modules in the entry configuration to enable capabilities such as HMR. It is best to exclude these client module from lazy compilation by configuring test
.
If not excluded and lazy compilation of entry is enabled, this client will not be compiled when accessing the page for the first time, so an additional refresh is needed to make it take effect.
For example: