8000 Distribute src as ES Modules · Issue #534 · evilsoft/crocks · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Distribute src as ES Modules #534
Open
@semmel

Description

@semmel

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, or 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:

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0