Skip to content

Commit

Permalink
docs: add stats data (#6937)
Browse files Browse the repository at this point in the history
* docs: add stats data

* docs: add stats data

* Apply suggestions from code review

---------

Co-authored-by: neverland <chenjiahan.jait@bytedance.com>
  • Loading branch information
LingyuCoder and chenjiahan authored Jun 26, 2024
1 parent 62b396a commit 9076d37
Show file tree
Hide file tree
Showing 4 changed files with 575 additions and 2 deletions.
3 changes: 2 additions & 1 deletion website/docs/en/api/_meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@
"type": "dir",
"name": "plugin-api",
"label": "Plugin API"
}
},
"stats"
]
285 changes: 285 additions & 0 deletions website/docs/en/api/stats.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,285 @@
import WebpackLicense from '@components/webpack-license';

<WebpackLicense from="https://webpack.docschina.org/api/stats/" />

# Stats Data

While using Rspack, you can use the following command to generate a JSON file of the statistics module information to analyze the module dependency relationship:

```bash
# Generate a statistical information JSON file named `compilation-stats.json`
$ rspack --json=compilation-stats.json
```

## Structure

The top-level structure of the output object is as follows:

```json
{
// Fixed simulated webpack version number for compatibility with plugins
"version": "5.75.0",
// Current version number of rspack
"rspackVersion": "0.7.4",
// Compilation specific hash
"hash": "",
// Compilation time in milliseconds
"time": 2469,
// The `output.publicPath` in the configuration
"publicPath": "auto",
// Path to rspack output directory
"outputPath": "/",
// Chunk name to emitted asset(s) mapping
"assetsByChunkName": {
"main": ["main.js", "main.js.map"],
"named-chunk": ["named-chunk.js", "named-chunk.js.map"]
},
// List of asset objects, refer to the "Asset Object"
"assets": [],
// List of chunk objects, refer to the "Chunk Object"
"chunks": [],
// List of module objects, refer to the "Module Object"
"modules": [],
// Map of entry objects, refer to the "Entry Object"
"entrypoints": {},
// List of error objects, refer to the "Error/Warning Object"
"errors": [],
// Number of errors
"errorsCount": 0,
// List of warning objects, refer to the "Error/Warning Object"
"warnings": [],
// Number of warnings
"warningsCount": 0
}
```

## Asset Object

Each asset object represents an output file emitted from the compilation, and its structure is as follows:

```json
{
"type": "asset",
// The `output` filename
"name": "main.js",
// The size of the file in bytes
"size": 2467,
// Indicates whether or not the asset made it to the `output` directory
"emitted": true,
// The chunks this asset contains
"chunkNames": ["main"],
// The chunk IDs this asset contains
"chunks": ["909"],
"info": {
// A flag telling whether the asset is only used for development and doesn't count towards user-facing assets
"development": false,
// A flag telling whether the asset ships data for updating an existing application (HMR)
"hotModuleReplacement": false,
// sourceFilename when asset was created from a source file (potentially transformed)
"sourceFilename": "originalfile.js"
}
}
```

## Chunk Object

Each chunk object represents a group of modules known as a chunk, and its structure is as follows:

```json
{
"type": "chunk",
// Whether the chunk went through Code Generation
"rendered": true,
// Whether the chunk is loaded on initial page load or on demand
"initial": false,
// Whether the chunk contains the rspack runtime
"entry": false,
// Size of the chunk (in bytes)
"size": 5382,
// Total size of chunk modules group by the output type (in bytes)
"sizes": {
"asset": 5303,
"javascript": 79
},
// List of chunk names contained within this chunk
"names": ["named-chunk"],
// The runtime used by the chunk
"runtime": ["main"],
// The list of product files contained in the chunk
"files": ["named-chunk.js"],
// The list of attached product files contained in the chunk
"auxiliaryFiles": ["named-chunk.js.map"],
// Chunk hash
"hash": "",
// Chunk ID
"id": "906",
// List of idHints of the cache groups hit when splitting chunks (need to enable `optimization.splitChunks`).
"idHints": [],
// Sibling chunk IDs
"siblings": [],
// Parent chunk IDs
"parents": ["909"],
// Children chunk IDs
"children": [],
// List of origins describing how the given chunk originated
"origins": [
{
// Path to the module
"module": "project_root/index.js",
// The identifier of the module
"moduleIdentifier": "project_root/index.js",
// Relative path to the module
"moduleName": "./index.js",
// Lines of code that generated this chunk
"loc": "2:0-50",
// The dependency request in the module
"request": "./dependent"
}
],
// List of modules contained in the chunk, for details, refer to the "Module Object"
"modules": []
}
```

## Module Object

Each module object represents a module in the dependency graph, and its structure is as follows:

```json
{
"type": "module",
// Module ID
"id": 670,
// Module source type
"moduleType": "javascript/auto",
// A unique identifier used internally
"identifier": "project_root/a.js",
// Path to the actual file
"name": "./a.js",
// Estimated size of the module in bytes
"size": 19,
// Total size of module group by the output type (in bytes)
"sizes": {
"javascript": 19
},
// Whether the module went through loaders and parsing
"built": true,
// Whether the module went through code generation
"codeGenerated": true,
// Whether the module is run during the compilation (you can see it while using css-extract)
"buildTimeExecuted": false,
// Whether the module is cached
"cached": false,
// Whether the module can be cached
"cacheable": true,
// Whether the module is optional, and if it is optional, only a warning will be issued when the module is not found
"optional": false,

// List of reasons why the module is introduced, similar to the structure of chunk.origins
"reasons": [],
// Unique identifier of the parent module
"issuer": "project_root/index.js",
// Parent module ID
"issuerId": 237,
// Path to the actual file of parent module
"issuerName": "./index.js",
// Reference path from the entry to the current module
"issuerPath": [
{
"identifier": "project_root/index.js",
"name": "./index.js",
"id": 237
}
],
// Absolute path used by the module for conditional matching (usually the resource path)
"nameForCondition": "project_root/a.js",
// The top-down index of the module in the ChunkGroup
"preOrderIndex": 1,
// The bottom-up index of the module in the ChunkGroup
"postOrderIndex": 1,
// The level in module graph
"depth": 1,

// Whether the module is not included by any chunk
"orphan": false,
// List of IDs of chunks that contain the module
"chunks": [522],
// List of assets generated by the module
"assets": [],

// Whether the module compiles failed
"failed": false,
// Number of errors
"errors": 0,
// Number of warnings
"warnings": 0,

// Used module exports, true indicates that all are used, string[] indicates that some fields are used (need to enable `optimization.usedExports`)
"usedExports": true,
// List of fields exported by the module (need to enable `optimization.providedExports`)
"providedExports": ["a"],
// Optimization bailout reasons (need to enable `optimization.concatenateModules`)
"optimizationBailout": [],
// If current module is generated by scope hoisting, this is the list of the original modules (need to enable `optimization.concatenateModules`)
"modules": [],

// Source code
"source": "export const a = 1;",

// The compilation time statistics for each phase (in milliseconds, need to enable `profile`)
"profile": {
// Resolving the module
"resolving": 13,
// Compiling the module
"building": 31
}
}
```

## Entry Object

Each entry object represents an entry chunk group, and its structure is as follows:

```json
"main": {
// Name of the entry
"name": "main",
// Assets generated by the entry
"assets": [
{
// File name
"name": "main.js",
// File size
"size": 2467
}
],
// Total size of the assets generated by the entry
"assetsSize": 2467,
// List of IDs of the chunks included
"chunks": ["909"],
}
```

## Error/Warning Object

Each error/warning object represents an error/warning threw during the build process, and its structure is as follows:

```json
{
// Visual message of the error/warning
"message": "
Γ— Resolve error: Can't resolve './not-exists' in './index.js'
╭─[1:1]
1 β”‚
3 β”‚ import('./not-exists');
Β· ─────────────────────
╰────
",
// Unique identifier of the module where the error/warning occurs
"moduleIdentifier": "project_root/index.js",
// Relative path of the module where the error/warning occurs
"moduleName": "./index.js",
// ID of the module where the error/warning occurs
"moduleId": "10"
}
```
3 changes: 2 additions & 1 deletion website/docs/zh/api/_meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@
"type": "dir",
"name": "plugin-api",
"label": "插仢 API"
}
},
"stats"
]
Loading

0 comments on commit 9076d37

Please sign in to comment.