Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build Dual CommonJS/ES module package #605

Merged
merged 7 commits into from
Aug 23, 2022

Conversation

semmel
Copy link
Contributor

@semmel semmel commented Aug 11, 2022

Use ES module loader in browser, Node and bundlers – e.g.

  • import {Maybe} from 'purify-ts/Maybe.js'
  • import {Maybe} from 'purify-ts/Maybe' (requires import-map in browsers)
  • import("purify-ts/Maybe").then(m => { globalThis.Maybe = m.Maybe; });
  • use rollup with plugin @rollup/plugin-node-resolve
  • follows Node.js' docs for Dual CommonJS/ES module packages

CommonJS support should be untouched

node -e 'const Maybe = require("purify-ts").Maybe; console.log(Maybe.of("foo").orDefault("bar"));'
--> "foo"

Two additional dev-dependencies

Unfortunately the TypeScript compiler still generates bare import specifiers in the js files. Many ways to "Provide a way to add the '.js' file extension to the end of module specifiers" are available to the JS community.

I choose the compiler plugin because both dependencies are themselves dependency-free – so less of a hassle to keep them up-to-date.

@gigobyte
Copy link
Owner

Published 1.3.0-rc1 and tested the output with commonjs, mjs and tsc - all work!

Thanks for the contribution!

@gigobyte gigobyte merged commit 3a68530 into gigobyte:master Aug 23, 2022
@semmel semmel deleted the distribute-es-module branch October 1, 2022 14:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants