evilsoft / evilsoft/crocks

Distribute src as ES Modules

Open
#534 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
1.6k
Forks
103
PR merge metrics
No merged PRs in 30d

Description

Shipping src as ES modules has obvious benefits: E.g.
- loading only the parts of crocks what you need (i.e. treeshaking),
- bundler-free development in browsers and
- supporting projects using another JS loader.

With #264 an attempt to migrate crocks to ES modules has been started.

### Idea:
In the meantime I suggest generating ES modules files from every CommonJS file in `/src` in the build step. This achieves almost the same as the conversion of all source files – some code will be duplicated though.

#### Dead ends
CJS → ESM Conversion tools are either abandoned like [nolanlawson/cjs-to-es6](https://github.com/nolanlawson/cjs-to-es6), or [wessberg/cjstoesm](https://github.com/wessberg/cjstoesm) produces errors converting the crocks codebase.

### Solution:
I've employed *rollup* with a quite standard config file of about 40 lines code in my tests. It generates a `dist/esm` folder, which can be mapped via
- `exports` section in package.json for bundlers and Node, or
- *importmap* in browsers

to bare ES module import specifiers.

Quite similar to the ReadMe instructions, for example:
```javascript
import { logic } from 'crocks';
import Maybe from 'crocks/Maybe';
import pointfree from 'crocks/pointfree';
// not quite sure about this one yet:
// no problem in Node, in browser depends on importmap capabilities
import either from 'crocks/pointfree/either';
// or
import either from '../node_modules/crocks/dist/esm/pointfree/either.js';
const
{and, not} = logic,
{ option } = pointfree,
mFoo = Maybe.of("bar"),
mNothing = Maybe.Nothing(),
// …
```

My contribution would involve adding rollup as dev depondency, adding the `export` section in `package.json` and a `rollup.config.js` file.

Should I attempt a PR?

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.