build @rspack/cli and napi binding by run pnpm install && pnpm -w build:cli:debug
In VS Code's Run and Debug tab, select debug-rspack to start debugging the initial launch of @rspack/cli. This task can be configured in .vscode/launch.json, which launches the Node and Rust debugger together.
debug builds are TRACE, DEBUG, INFO, WARN and ERROR
Use the RSPACK_PROFILE environment variable for displaying trace information
RSPACK_PROFILE=TRACE=layer=logger rspack build
# filter for an eventRSPACK_PROFILE='TRACE=layer=logger&filter=rspack_core::compiler::compilation' rspack build
# with logger levelRSPACK_PROFILE='TRACE=layer=logger&filter=rspack_core::compiler::compilation=info' rspack build
# filter logs across multiple modulesRSPACK_PROFILE='TRACE=layer=logger&filter=rspack_core::compiler::compilation,rspack_core::build_chunk_graph::code_splitter' rspack build
# [fn_name] will show:# - all functions calls to `fn_name`# - the arguments(except for these in the `skip` list)# - everything until this function returnsRSPACK_PROFILE='TRACE=layer=logger&filter=[build_chunk_graph]' rspack build
# compilation::chunk_asset is a custom instrument nameRSPACK_PROFILE='TRACE=layer=logger&filter=[compilation:chunk_asset]' rspack build
# log a specific function by their argumentsRSPACK_PROFILE='TRACE=layer=logger&filter=[compilation:chunk_asset{filename="main\.js"}]' rspack build
# It support regexp expressionRSPACK_PROFILE='TRACE=layer=logger&filter=[compilation:chunk_asset{filename=".*\.js"}]' rspack build
# disable ansi color escape codesNO_COLOR=1RSPACK_PROFILE=TRACE=layer=logger rspack build
It's necessary to configure two debug configurations within in .vscode/launch.json.
attach for node:
{
"name": "attach:node",
"request": "attach", // refer: https://code.visualstudio.com/docs/editor/debugging#_launch-versus-attach-configurations
"type": "node",
// `9229` is the default port of message
"port": 9229,
}
and launch for lldb
{
"name": "launch:rust-from-node",
"request": "launch",
"type": "lldb", // it means we use `lldb` to launch the binary file of `node`
"program": "node",
"args": [
"--inspect",
"--enable-source-maps",
"${workspaceFolder}/packages/rspack-cli/bin/rspack",
"build",
"-c",
"${workspaceFolder}/examples/basic/rspack.config.js",
],
// `cwd` is just for repack find the correctly entry.
"cwd": "${workspaceFolder}/examples/basic/",
}
Next, we can utilize compounds to amalgamate the two commands: