-
-
Notifications
You must be signed in to change notification settings - Fork 123
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
Dual-build for ESM and CJS #164
Conversation
39f8139
to
45bdfcc
Compare
package.json
Outdated
"browser": "dist/index.browser.mjs", | ||
"main": "dist/index.cjs", | ||
"module": "dist/index.mjs", | ||
"types": "dist/index.d.ts", | ||
"targets": { | ||
"browser": { | ||
"isLibrary": true, | ||
"outputFormat": "esmodule", | ||
"source": "src/index.browser.ts", | ||
"sourceMap": true | ||
}, | ||
"main": { | ||
"isLibrary": true, | ||
"outputFormat": "commonjs", | ||
"source": "src/index.ts", | ||
"sourceMap": true | ||
}, | ||
"module": { | ||
"context": "node", | ||
"isLibrary": true, | ||
"outputFormat": "esmodule", | ||
"source": "src/index.ts", | ||
"sourceMap": true | ||
}, | ||
"browser-bundle": { | ||
"context": "browser", | ||
"distDir": "dist/", | ||
"outputFormat": "global", | ||
"source": "src/index.browser-bundle.ts" | ||
}, | ||
"types": { | ||
"source": "src/index.ts" | ||
} | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the complete Parcel configuration. When you run parcel build
it reads this data to know how to behave.
"@types/uuid": "^8.3.4", | ||
"@types/ws": "^8.2.2", | ||
"buffer": "^6.0.3", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Downstream clients may actually need these dependencies if they're building for the browser, so I moved them out of devDependencies
.
571c5b3
to
79ecfe6
Compare
Signed-off-by: Mario Kozjak <kozjakm1@gmail.com>
Converting to draft for a moment; gotta figure out a way to build a typedef for the browser bundle (ie. it needs to omit |
79ecfe6
to
d87f162
Compare
OK, Parcel is not appropriate for this multi-package build (browser, node, iife). I've replaced it with the build pipeline that we use ourselves to build multiple packages, retested it, and added Next.js test plans for both App router and Pages router. Ready to review. |
d87f162
to
a5679fb
Compare
a5679fb
to
beb53f7
Compare
tsconfig.json
Outdated
"noEmit": true, | ||
"declaration": false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only used for typechecking now, not for building.
globals: { | ||
buffer: true, | ||
}, | ||
polyfills: { | ||
buffer: true, | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When building browser-bundle.js
, include the buffer
polyfill.
Amazing work, @steveluscher! Thanks much. |
I hope this fixes everyone’s build issues once and for all. Sorry for the wild ride, everyone. Once this works it should let y’all:
|
Summary
In this PR we introduce an ESM build. This should ensure compatibility with ESM build pipelines, including:
…and all of the other ESM-based bundlers that folks have been having trouble with since v8.
This should be released as v9 because of how much change there is.
Changes
dist/
to pick out one particular module (eg.WebSocketBrowserImpl
). More about this, including an example, inAPI.md
. Anything you don't use among the exports should be tree-shaken away by your optimizing compiler (eg. if you only useWebSocket
thenClient
should get tree-shaken away).dist/
.package.json
dist/
,README.md
,LICENSE
, andpackage.json
Test plan
Unit tests
@solana/web3.js
Applied this diff and rebuilt. IIFE bundle worked.
Create React App
App.js
Next.js with App Router
page.tsx
npm run dev
Next.js with App Router
_app.tsx
npm run dev