chore(core): cjs and esm distribution of core, enable @botonic/core tree-shaking #1826
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
@botonic/core
package as/lib/cjs
andlib/esm
. (ref: https://blog.logrocket.com/publishing-node-modules-typescript-es-modules/)sideEffects
flag to false to facilitate webpack to tree-shake the library.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:
when using webpack, the resolved library will depend on how we import the code.
e.g.:
by compiling this with webpack in production mode:
npx webpack
we end up with a minified file of4.0KB
.reason: ESM packages are tree-shakeable and will only bundle the
isFunction
method.whereas by compiling this with webpack in production mode:
npx webpack
we end up with a minified file of216.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.