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

chore(core): cjs and esm distribution of core, enable @botonic/core tree-shaking #1826

Merged
merged 1 commit into from
Sep 8, 2021

Conversation

vanbasten17
Copy link
Contributor

@vanbasten17 vanbasten17 commented Sep 1, 2021

Description

Distributing it with CJS will allow us to use it in environments like Node.js, whereas esm will allow us to use it in browser and applications using webpack.

Despite having the following two lines declared @botonic/core:

"main": "./lib/cjs/index.js",
"module": "./lib/esm/index.js",

when using webpack, the resolved library will depend on how we import the code.
e.g.:

import { isFunction } from '@botonic/core' // --> will load automatically /lib/esm version of the code.
console.log(isFunction)

by compiling this with webpack in production mode: npx webpack we end up with a minified file of 4.0KB.
reason: ESM packages are tree-shakeable and will only bundle the isFunction method.

const { isFunction } = require('@botonic/core') // --> will load automatically /lib/cjs version of the code.
console.log(isFunction)

whereas by compiling this with webpack in production mode: npx webpack we end up with a minified file of 216.0KB.
reason: CJS packages are not tree-shakeable and will bundle the isFunction along with the rest of the code exported in core's index.

Copy link
Contributor

@asastre asastre left a comment

Choose a reason for hiding this comment

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

Very nice! 👏 👏

@vanbasten17 vanbasten17 merged commit a2d1f71 into master Sep 8, 2021
@vanbasten17 vanbasten17 deleted the core/improvements branch September 8, 2021 08:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants