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

chore(package): switch distribution build to Babel #1169

Closed
wants to merge 1 commit into from

Conversation

layershifter
Copy link
Member

@layershifter layershifter commented Apr 4, 2019

Fixes #508.


Improve bundling :yay

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

New distribution structure

Each package will have the following structure:

  • dist-node - single bundled file with CommonJS modules distribution
  • dist-src - source files compiled with Babel, has the same structure as project, preserves ability to pick single files from project
  • dist-types - contains bundle single file with types (expect @stardust-ui/react, see below why)
  • dist-web - an ESM distribution of package via single file, built & optimized to run in most web browsers, tree shaking will work properly in this case, don't worry 馃摝

Single file distribution becomes standard, even React is distributed via single file. Current distribution for ES modules includes 1,556 files, it's definitely better to have one for bundlers 鉂わ笍

Uses @pika/pack

To get the structure above no custom code is required, everything is done using @pika/pack, this allow us to add custom stages to their pipeline and make complicated bundling easily 馃憤

Configured @babel/preset-env

We use .browserslistrc to target required browsers, this setting can be adjusted later, current config.

Adds @pika/plugin-build-types

It's a custom plugin that will bundle definitions to a single file with rollup-plugin-dts, the nicest thing is that it will contain only publicly exported definitions 馃惡

Switch to @babel/runtime

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

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

TS Project References for @stardust-ui/react

There is only one reason to introduce this: our withSafeTypeForAs() creates very complicated TS definitions and these definitions can't be bundled due some bugs in rollup-plugin-dts 馃挘

https://cdn.jsdelivr.net/npm/@stardust-ui/react@0.30.0/dist/es/components/Chat/Chat.d.ts
https://cdn.jsdelivr.net/npm/@stardust-ui/react@0.31.0/dist/es/components/Chat/Chat.d.ts

Because of this, the PR also introduces changes to our tsconfig.json's to use Project References feature. It was designed also to handle monorepo cases (microsoft/TypeScript#25376).

When you reference a project, new things happen:

  • Importing modules from a referenced project will instead load its output declaration file (.d.ts)
  • If the referenced project produces an outFile, the output file .d.ts file鈥檚 declarations will be visible in this project

https://www.typescriptlang.org/docs/handbook/project-references.html

This feature allows to properly define rootDir option in tsconfig.json and generate output proper typings by compiler:

image

Without the references feature it will fail because TypeScript doesn't know anything about modules structure:
image

Ongoing stuff

  • fix some HMR issues
  • introduce babel-transform-remove-proptypes

@layershifter layershifter changed the title feat(Ref): extract to a separate package, update bundling [WIP] feat(Ref): extract to a separate package, update bundling Apr 9, 2019
@layershifter layershifter changed the title [WIP] feat(Ref): extract to a separate package, update bundling [WIP] chore(package): use pikapkg to bundle packages May 5, 2019
@layershifter layershifter force-pushed the feat/extract-ref branch 5 times, most recently from 81772f4 to 0e9ec0b Compare May 10, 2019 16:23
@codecov
Copy link

codecov bot commented May 13, 2019

Codecov Report

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

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1169   +/-   ##
=======================================
  Coverage   73.51%   73.51%           
=======================================
  Files         786      786           
  Lines        5863     5863           
  Branches     1703     1703           
=======================================
  Hits         4310     4310           
  Misses       1547     1547           
  Partials        6        6
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 f09083d...bb388ca. Read the comment docs.

@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-ref/package.json

package before after
@babel/runtime-corejs2 - ^7.4.5

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

package before after
@babel/runtime-corejs2 - ^7.4.5

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

package before after
@babel/runtime-corejs2 - ^7.4.5

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

package before after
@pika/pack - ^0.3.7
@pika/plugin-build-node - ^0.4.0
@pika/plugin-build-web - ^0.4.0
@pika/plugin-standard-pkg - ^0.4.0
babel-plugin-lodash - ^3.3.4
cross-env - ^5.2.0
rollup - ^1.11.3
rollup-plugin-dts - ^0.15.1
typescript - ^3.3.3333

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

package before after
@babel/runtime-corejs2 - ^7.4.5

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

package before after
@babel/runtime-corejs2 - ^7.4.5

Changed dependencies in packages/react/package.json

package before after
@babel/runtime-corejs2 - ^7.4.5

Generated by 馃毇 dangerJS

@layershifter layershifter changed the title [WIP] chore(package): use pikapkg to bundle packages chore(package): use pikapkg to bundle packages May 28, 2019
@layershifter layershifter changed the title chore(package): use pikapkg to bundle packages chore(package): switch distribution to Babel May 28, 2019
@layershifter layershifter changed the title chore(package): switch distribution to Babel chore(package): switch distribution build to Babel May 28, 2019
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
2 participants