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

ES Module Support #455

Open
wants to merge 1 commit into
base: v3.4.x
Choose a base branch
from
Open

ES Module Support #455

wants to merge 1 commit into from

Conversation

Pessimistress
Copy link

Related: #444

The package will support the following usage in Node:

await import('gl-matrix')
await import('gl-matrix/mat4')
require('gl-matrix')
require('gl-matrix/mat4')

by making the following changes to the published package.json:

+ "type": "module",
- "main": "cjs/index.js",
+ "main": "cjs/index.cjs",
  "module": "esm/index.js",
+ "exports": {
+   ".": {
+     "require": "./cjs/index.cjs",
+     "import": "./esm/index.js"
+   },
+   "./mat2": {
+     "require": "./cjs/mat2.cjs",
+     "import": "./esm/mat2.js"
+   },
+   "./mat2d": {
+     "require": "./cjs/mat2d.cjs",
+     "import": "./esm/mat2d.js"
+   },
+   ...

@donmccurdy
Copy link

Related:

I've been using gl-matrix in a library that is going ESM-only and needs to support Node.js, so my workaround for the time being is to configure my build tool (microbundle) to inline the gl-matrix functions I need, rather than keeping the gl-matrix npm package as a production dependency. This is working for now, but I do look forward to full ESM support and package#exports in v4, if that's still the plan!

@ibgreen
Copy link

ibgreen commented Jan 30, 2023

In the same vein, we are about upgrade math.gl 4.0 to type: module and unless this (or something equivalent) lands, we will need to replace our gl-matrix dependency with a local fork (at least temporarily).

@mikeymaxdb
Copy link

I'm building my project on v4 and it would be awesome to just import from 'gl-matrix' instead of from 'gl-matix/dist/esm'!

@lkmill
Copy link
Contributor

lkmill commented Jul 30, 2023

This should probably not be merged into the 3.4.x branch, as it would be a breaking change.

Full ESM support (including package exports) was merged in #432 and released in version 3.4.0, but reversed in 3.4.{1,2,3} (due to #439). The ESM related changes seem to remain in the master branch, but I'm not sure what the release plan is there. Perhaps @toji or @stefnotch knows more...

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.

5 participants