Skip to content
This repository was archived by the owner on Aug 4, 2021. It is now read-only.
This repository was archived by the owner on Aug 4, 2021. It is now read-only.

Optimize module.exports = … pattern #4

@Swatinem

Description

@Swatinem

This is an extremely common pattern used in cjs modules. rollup-plugin-commonjs currently creates suboptimal code for that, see the example from zloirock/core-js#125 (comment):

var exports$198 = {};
var module$198 = { 'exports': exports$198 };
module$198.exports = require$$0$5.document && document.documentElement;

// OR

var exports$129 = {};
var module$129 = { 'exports': exports$129 };
module$129.exports = function(it){
  return typeof it === 'object' ? it !== null : typeof it === 'function';
};

If rollup-plugin-commonjs were a little bit smarter, it could avoid allocating the unused exports var/object in that case.
It it were even smarter, it may also be possible to avoid the modules map too, but I guess that would depend on the importer side, so it might not be feasible.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions