3 ms·
One of the optimizations we do in Bun.build() is to automatically rewrite imports/requires of CommonJS modules shaped like this if (process.env.NODE_ENV ==
by Jarred 3y ago
One of the optimizations we do in Bun.build() is to automatically rewrite imports/requires of CommonJS modules shaped like this
if (process.env.NODE_ENV === "development") {
module.exports = require("./another-file.dev.js")
} else {
module.exports = require("./another-file.js")
}
Into the destination path, removing this module entirely
I tried to make this work for ESM too, but there were too many edgecases due to module namespace objects being observable (`import * as `)
A similar thing could be done for barrel files with `"sideEffects": false`. We don't currently follow nested default exports which makes this harder to do as effectively (we do support "sideEffects": false)