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

chore(babel): switch to Babel in distribution #1404

Merged
merged 5 commits into from Jun 12, 2019
Merged

Conversation

layershifter
Copy link
Member

@layershifter layershifter commented May 28, 2019

Fixes #508.

This PR is a final step in Babel migration and aims to improve and simplify our bundling, too.

Use gulp-babel

Now we use gulp-babel to transpile files.

Switch to @babel/runtime

As we switched to Babel, we also replaced tslib with @babel/runtime.

why @babel/runtime over @babel/runtime-corejs*?

It's commonly used by other libraries:

babel-plugin-lodash

This PR also introduces the first babel plugin that aims to optimize bundle size. Lodash is CJS and can't be treeshaked, it means that import _ from 'lodash' will include the whole library (70 Kb) 😭

This plugin will transform import _ from 'lodash' to import _map from 'lodash/map' where _map is module required in your file.

image

Bundle size

Benefits in bundle size are received from decreasing lodash: from 97Kb to 51Kb.

@stardust-ui/react-proptypes

@stardust-ui/react-component-ref

Includes @stardust-ui/react-proptypes: we definitely need to perform advanced optimizations like this https://github.com/airbnb/prop-types/blob/master/index.js.

@stardust-ui/react

About increase of main package: self@0.32 - 448KB vs self@0.33 - 536KB

@codecov
Copy link

codecov bot commented May 28, 2019

Codecov Report

Merging #1404 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1404   +/-   ##
=======================================
  Coverage   73.63%   73.63%           
=======================================
  Files         808      808           
  Lines        6092     6092           
  Branches     1755     1755           
=======================================
  Hits         4486     4486           
  Misses       1601     1601           
  Partials        5        5
Impacted Files Coverage Δ
packages/react/src/index.ts 100% <ø> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 921d4e5...e8a9e3e. Read the comment docs.

@layershifter layershifter changed the title Chore/babel chore(babel): switch to Babel in distribution May 28, 2019
@DustyTheBot
Copy link
Collaborator

DustyTheBot commented May 28, 2019

Warnings
⚠️ There are no updates provided to CHANGELOG. Ensure there are no publicly visible changes introduced by this PR.
⚠️ Package (or peer) dependencies changed. Make sure you have approval before merging!

Changed dependencies in packages/react-component-nesting-registry/package.json

package before after
@babel/runtime - ^7.1.2

Changed dependencies in packages/docs-components/package.json

package before after
@babel/runtime - ^7.1.2

Changed dependencies in packages/react/package.json

package before after
@babel/runtime - ^7.1.2

Changed dependencies in packages/react-proptypes/package.json

package before after
@babel/runtime - ^7.1.2

Changed dependencies in packages/react-component-ref/package.json

package before after
@babel/runtime - ^7.1.2

Changed dependencies in packages/react-component-event-listener/package.json

package before after
@babel/runtime - ^7.1.2

Changed dependencies in packages/internal-tooling/package.json

package before after
babel-plugin-lodash - ^3.3.4

Generated by 🚫 dangerJS

@layershifter
Copy link
Member Author

@kuzhelov
Copy link
Contributor

nit: for bundle size stat in description, it will be more representative to share decrease in lodash size - (from 97Kb to 51Kb), as this is exactly the thing changes were aimed on

Copy link
Contributor

@kuzhelov kuzhelov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this is announced as a concluding step for Babel transition, would like to point out that there is a regression we currently have in comparison to the original TS-based setup: currently our .ts config files are not checked for type safety before executed.

This may introduce problems for rename refactorings, especially, when it is about changing the variable names that contain path values. We should ensure that our config code will be checked for type correctness before being executed - behavior we've had before.

Lets file an issue for that, to keep this piece of work tracked.

@@ -23,8 +28,10 @@ module.exports = api => {
const plugins = [
'@babel/plugin-proposal-class-properties',
'@babel/plugin-syntax-dynamic-import',
'@babel/plugin-transform-runtime',
]
['@babel/plugin-transform-runtime', { corejs: false, useESModules }],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

false is the default value for corejs option, seems that we can omit it

}

module.exports = api => {
const isNode = api.caller(isBabelRegister) || api.caller(isJest)
const isDistBuild = api.caller(isDistCaller)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: probably, isDistBundle name will better reflect semantics and related optimizations applied for this scenario

@layershifter layershifter merged commit 34f4b76 into master Jun 12, 2019
@delete-merged-branch delete-merged-branch bot deleted the chore/babel branch June 12, 2019 13:32
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RFC: switch to Babel
3 participants