mirror of
https://github.com/oven-sh/bun
synced 2026-02-13 04:18:58 +00:00
feat: enable DCE for process.isBun when target is bun
When bundling with --target=bun, process.isBun is now replaced with the literal value `true`, enabling dead code elimination for conditional code paths. This provides an easy way to write Bun-specific code that gets optimized away during bundling.
Example:
```js
if (process.isBun) {
// This code is kept when --target=bun
bunSpecificLogic();
} else {
// This code is eliminated when --target=bun
nodeSpecificLogic();
}
```
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1510,6 +1510,15 @@ pub fn definesFromTransformOptions(
|
||||
.value = .{ .e_undefined = .{} },
|
||||
}));
|
||||
}
|
||||
|
||||
// Set process.isBun to true for DCE when target is bun
|
||||
if (!user_defines.contains("process.isBun")) {
|
||||
_ = try environment_defines.getOrPutValue("process.isBun", .init(.{
|
||||
.valueless = false,
|
||||
.original_name = "process.isBun",
|
||||
.value = .{ .e_boolean = .{ .value = true } },
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
const resolved_defines = try defines.DefineData.fromInput(user_defines, drop, log, allocator);
|
||||
|
||||
Reference in New Issue
Block a user