Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimisation #106

Merged
merged 4 commits into from Sep 17, 2016

Conversation

Projects
None yet
3 participants
@Rich-Harris
Copy link
Contributor

commented Sep 17, 2016

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

4 checks passed

continuous-integration/appveyor/branch AppVeyor build succeeded
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details

@Rich-Harris Rich-Harris deleted the optimisation branch Sep 17, 2016

@montogeek

This comment has been minimized.

Copy link

commented Sep 17, 2016

Will this work with Lodash?

@Rich-Harris

This comment has been minimized.

Copy link
Contributor Author

commented Sep 17, 2016

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

This comment has been minimized.

Copy link

commented Sep 17, 2016

Thanks!

@jdalton

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link

commented Sep 19, 2016

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.