-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Add ESM build for browsers #342
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,17 @@ | |
}, | ||
"main": "lib/main.js", | ||
"browser": "lib/browser.js", | ||
"module": "lib/browser.mjs", | ||
"exports": { | ||
".": { | ||
"browser": { | ||
"module": "./lib/browser.mjs", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
"script": "./lib/browser.js" | ||
}, | ||
"node": "./lib/main.js" | ||
}, | ||
"./": "./" | ||
}, | ||
"types": "lib/main.d.ts", | ||
"directories": { | ||
"bin": "bin" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,6 +89,16 @@ function buildWasmLib(esbuildPath) { | |
'--define:WEB_WORKER_SOURCE_CODE=' + JSON.stringify(wasmExecMinCode + workerMinCode), | ||
], { cwd: repoDir }).toString() | ||
fs.writeFileSync(path.join(libDir, 'browser.js'), umdPrefix + browserJs.trim() + umdSuffix) | ||
|
||
// Generate "npm/esbuild-wasm/browser.mjs" | ||
const browserMjs = childProcess.execFileSync(esbuildPath, [ | ||
path.join(repoDir, 'lib', 'browser.ts'), | ||
'--bundle', | ||
'--target=es2020', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I set it to a modern target since the assumption for the |
||
'--format=esm', | ||
'--define:WEB_WORKER_SOURCE_CODE=' + JSON.stringify(wasmExecMinCode + workerMinCode), | ||
], { cwd: repoDir }).toString() | ||
fs.writeFileSync(path.join(libDir, 'browser.mjs'), browserMjs.trim()) | ||
} | ||
|
||
exports.buildBinary = () => { | ||
|
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 change was needed, because without it, ESM shim code was being included in the ESM build. I switched it so that now it uses a default export as well as named exports. I took a look at the outputs of the various bundles and it seems correct. The bundle that I'm least sure about is the
browser.js
bundle, but it looks right as far as I can tell.