The stats
object that is passed as a second argument of the rspack()
callback, is a good source of information about the code compilation process. It includes:
The Stats
object provides two important methods:
toJson()
: Output information in the form of a Stats JSON object, which is often used in analysis tools.toString()
: Output information in the form of a string, which is often used in the CLI tools.Rspack also provides StatsFactory
and StatsPrinter
to fine-grained control the output object or string.
Create a stats object related to a compilation through compilation.getStats()
or new Stats(compilation)
.
Can be used to check if there were errors while compiling.
Can be used to check if there were warnings while compiling.
Return the compilation information in the form of a Stats JSON object. The Stats configuration can be a string (preset value) or an object for granular control:
Return the compilation information in the form of a formatted string (similar to the output of CLI).
Options are the same as stats.toJson(options)
with one addition:
Here's an example of stats.toString()
usage:
Type: Compilation
Get the related compilation object.
Type: string
Get the hash of this compilation, same as Compilation.hash
.
When using MultiCompiler
to execute multiple compilation tasks, their compilation stats will be packaged as a MultiStats
object, which provides similar methods and properties as Stats
.
Type: string
Get the unique hash after merging the hashes of all compilations.
Used to check if there are errors during the compilation period, and only if there are no errors in all compilations will it return false
.
Used to check if there are warnings during the compilation period, and only if there are no warnings in all compilations will it return false
.
According to the stats configuration, generate all the stats json objects, wrap them in the children
field, and also summarize the errors
and warnings
.
Concatenate the stats output strings of all compilations according to the stats configuration.
Used to generate the stats json object from the Compilation, and provides hooks for fine-grained control during the generation process.
It can be got through compilation.hooks.statsFactory
. Or create a new one by new StatsFactory()
.
See StatsFactory hooks for more details.
The core method of StatsFactory
, according to the type
to specify the current data structure, find and run the corresponding generator to generate the stats json item.
The
StatsFactory
object only handles the calling of hooks, and the processing code of the corresponding type can be found inDefaultStatsFactoryPlugin
.
Used to generate the output string from the stats json object, and provides hooks for fine-grained control during the generation process.
It can be got through compilation.hooks.statsPrinter
. Or create a new one by new StatsPrinter()
.
See StatsPrinter hooks for more details.
The core method of StatsPrinter
, according to the type to specify the current data structure, find and run the corresponding generator to generate the output string of the stats item.
The
StatsPrinter
object only handles the calling of hooks, and the processing code of the corresponding type can be found inDefaultStatsPrinterPlugin
.