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

Optimisation #106

Merged
merged 4 commits into from
Sep 17, 2016
Merged

Optimisation #106

merged 4 commits into from
Sep 17, 2016

Conversation

Rich-Harris
Copy link
Contributor

This PR allows the majority of CommonJS modules to be transformed without wrapping. In other words, this...

// foo.js
module.exports = 42;

...becomes this...

var foo = 42;

export default foo;
export { foo as __moduleDefault };

...rather than this:

var foo = createCommonjsModule(function(module) {
  module.exports = 42;
});

export default foo;
export { foo as __moduleDefault };

In many cases this makes modules tree-shakeable. It doesn't yet optimise situations like this:

module.exports = {
  foo: foo,
  bar: bar
};

Will release as 5.0.0 (major version bump) as it depends on Rollup 0.35.

@Rich-Harris Rich-Harris merged commit 3cbb01b into master Sep 17, 2016
@Rich-Harris Rich-Harris deleted the optimisation branch September 17, 2016 00:19
@montogeek
Copy link

Will this work with Lodash?

@Rich-Harris
Copy link
Contributor Author

I'd recommend using lodash-es rather than lodash. This won't have any effect on the tree-shakeability of the library itself – all it means is that in a situation like this...

exports.a = 1;
exports.b = 2;

...where a is used in the bundle but b is not, the b can be removed. Previously there was no way to remove any code from a transformed CommonJS module.

@montogeek
Copy link

Thanks!

@jdalton
Copy link

jdalton commented Sep 19, 2016

@montogeek until things improve on the tree-shaking front of rollup and webpack 2 you'll still want to use babel-plugin-lodash for lodash or lodash-es.

@montogeek
Copy link

Thanks @jdalton It should be compatible with https://github.com/rollup/rollup-plugin-babel, right?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants