Start a compilation, and callbacked when the compilation is completed or aborted due to an error.
This API only supports one compilation at a time. Please call compiler.close
in the compiler.run
callback and wait for it to finish before executing compiler.run
again. Concurrent compilations will damage the output files.
Watching files and directories, start a compilation process after they change, and callbacked every time the compilation is completed or aborted due to an error.
This API only supports one compilation at a time. Please call compiler.close
in the compiler.watch
callback and wait for it to finish before executing compiler.watch
again. Concurrent compilations will damage the output files.
The Watching object provides the following methods:
watch
:
(files: string[], dirs: string[], missing: string[]): void
invalidate
:
(callback: () => void): void
suspend
:
(): void
resume
:
(): void
close
:
(callback: () => void): void
Create a compilation and run it, which is the basic method that compiler.run
and compiler.watch
depend on.
Close the current compiler, and handle low-priority tasks such as caching during this period.
Create a logger object that is not associated with any compilation, which is used to print global logs.
Create a cache object to share data in the build process.
Stop the read loop of the input file system, which internally contains a timer and may cause the process to still not be able to exit after calling compiler.close
.
Allows running another instance of Rspack inside of Rspack. However, as a child with different settings and configurations applied. It copies all hooks and plugins from the parent (or top-level compiler) and creates a child Compiler
instance. Returns the created Compiler
.
Running the child compiler, which will doing a complete compiling and generate the assets.
Whether this compiler is a child compiler.
See compiler hooks for more details.
typeof rspack
Get the exports of @rspack/core to obtain the associated internal objects. This is especially useful when you cannot directly reference @rspack/core
or there are multiple Rspack instances.
A common example is accessing the sources object in a Rspack plugin:
typeof rspack
Equivalent to compiler.rspack
, this property is used for compatibility with webpack plugins.
If the Rspack plugin you are developing needs to be webpack compatible, you can use this property instead of compiler.rspack
.
string
Get the name:
name
.createChildCompiler
.Current project root directory:
new Compiler
, it is the value passed in.rspack({})
, it is context configuration.Compiler
Get the root of the child compiler tree.
RspackOptionsNormalized
Get the full options used by this compiler.
boolean
Whether started through compiler.watch
.
Watching
Get the watching object, see watch method for more details.
boolean
Whether the compilation is currently being executed.
InputFileSystem
Get the proxy object used for reading from the file system, which has optimizations such as caching inside to reduce duplicate reading of the same file.
OutputFileSystem
Get the proxy object used for writing to the file system, fs
by default.
WatchFileSystem
Get the proxy object used for watching files or directories changes, which provides a watch
method to start watching, and passes in the changed and removed items in the callback.
The MultiCompiler
module allows Rspack to run multiple configurations in separate compilers. If the options parameter in the Rspack's JavaScript API is an array of options, Rspack applies separate compilers and calls the callback after all compilers have been executed.
It can also be created through new MultiCompiler
:
MultiCompiler
also provides some methods and attributes of the Compiler
.
Specify the dependency relationship between the compilers, using compiler.name
as the identifier, to ensure the execution order of the compilers.
Check whether the dependency relationship between the compilers is legal. If there is a cycle or a missing dependency, it will trigger the callback.
Execute the run
method of each compiler according to the dependency relationship to start the compilation process.
Execute the watch
method of each compiler according to the dependency relationship to start watching, and start a compilation process after the file changes.
Execute the close
method of each compiler to close them, and handle low-priority tasks such as caching during this period.
Execute the purgeInputFileSystem
of each compiler to stop the read loop of the file system
Create a logger object that is not associated with any compilation, which is used to print global logs.
Same with
compilers[0].getInfrastructureLogger()
Compiler[]
Get all included compilers.
RspackOptionsNormalized[]
Get all the full options used by the compilers.
InputFileSystem
Set the proxy object used for reading from the file system for each compiler.
OutputFileSystem
Set the proxy object used for writing from the file system for each compiler.
WatchFileSystem
Set the proxy object used for watching files or directories changes for each compiler.
boolean
Whether the compilation is currently being executed.