BrainJS / BrainJS/brain.js

Build as ES Module

Open
#946 0 comments 2 reactions 0 assignees View on GitHub
enhancement
Dominant language
TypeScript
Stars
14.9k
Forks
1.1k
PR merge metrics
No merged PRs in 30d

Description

## Summary

ES modules are widely supported: [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#browser_compatibility), [caniuse](https://caniuse.com/es6-module) and offer some advantages, like the ability of bundlers to do tree-shaking.

### Basic example

In the most basic setup, only a single line of code would have to change in [rollup.config.js](https://github.com/BrainJS/brain.js/blob/master/rollup.config.js):

```diff
output: [
{
file: pkg.main,
- format: 'cjs',
+ format: 'es',
sourcemap: true,
},
]
```

### Motivation

In my code currently I only use the `recurrent.LSTM()` class, and with the change above I observed a 56% bundle size reduction after tree-shaking. That value will obviously vary from user to user, but there will probably be a reduction in bundle size. If legacy support is important then it's possible to ship both, `cjs` and `esm` code, but I personally don't think that this is necessary.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.