Fp-ts: Ship ES6 module syntax along with CJS modules

Created on 3 Apr 2019  路  3Comments  路  Source: gcanti/fp-ts

Do you want to request a _feature_ or report a _bug_?

Feature

What is the current behavior?

I'm using bits and pieces of fp-ts in a library I'm building, but since fp-ts only ships CJS modules, a lot of code that goes unused by me ends up being bundled with my library anyway (since bundlers can't perform tree-shaking on CJS modules).

What is the expected behavior?

Ideally my library should only contain the parts of fp-ts that I'm using in my code.

In theory this should be a matter of running tsc a second time with --module=es6 and a separate outDir like --outDir=esm. You can then point bundlers that support es6 modules (e.g. webpack and rollup) to the es6 entry point by setting "module": "esm/index.js" in package.json.

If the codebase is free of side effects at import time (is it?), we can additionally tell bundlers that performing tree-shaking on this library is safe by setting "sideEffects": false in package.json (read more).

If it turns out that these are the only steps needed in practice as well, I might prepare a PR soon :-)

Most helpful comment

Ideally my library should only contain the parts of fp-ts that I'm using in my code.

@FruitieX it would be great, I'm very interested in providing the best possible use of fp-ts

If the codebase is free of side effects at import time (is it?)

AFAIK yes it is

If it turns out that these are the only steps needed in practice as well, I might prepare a PR soon

Nice, thanks!

All 3 comments

Ideally my library should only contain the parts of fp-ts that I'm using in my code.

@FruitieX it would be great, I'm very interested in providing the best possible use of fp-ts

If the codebase is free of side effects at import time (is it?)

AFAIK yes it is

If it turns out that these are the only steps needed in practice as well, I might prepare a PR soon

Nice, thanks!

@FruitieX just released 1.16.0 could you please try it out?

@gcanti it seems to work great, thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

josete89 picture josete89  路  3Comments

jollytoad picture jollytoad  路  4Comments

denistakeda picture denistakeda  路  4Comments

mohsensaremi picture mohsensaremi  路  3Comments

steida picture steida  路  4Comments