-
Notifications
You must be signed in to change notification settings - Fork 698
Description
What problem does this feature solve?
__toESM helper brings in many helper functions and makes the bundle size bigger.
__toESM helper exists to add the default export in some condition. While the condition is not known until runtime, we can know whether the default import is used or not. When the default import is not used, we can skip the __toESM helper.
For this input:
// index.js
import { foo } from './foo.cjs'
console.log(foo)
// foo.cjs
exports.foo = 'foo'Rolldown currently outputs:
// omit helper implementations
//#region foo.cjs
var require_foo = __commonJS({ "foo.cjs"(exports) {
exports.foo = "foo";
} });
//#endregion
//#region index.js
var import_foo = __toESM(require_foo());
console.log(import_foo.foo);
//#endregionBut since we know that the default import is not used, we can improve this to:
// omit helper implementations
//#region foo.cjs
var require_foo = __commonJS({ "foo.cjs"(exports) {
exports.foo = "foo";
} });
//#endregion
//#region index.ts
var import_foo = require_foo();
console.log(import_foo.foo);
//#endregionWhat does the proposed API look like?
Not an API change
Reactions are currently unavailable