Skip to content

Support Node.js ESM #39

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions build.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ shell.exec('wasm-pack build --target nodejs');
shell.mv('pkg', 'pkg.node');
shell.rm('pkg.node/{LICENSE,package.json,README.md,.gitignore}');

// Create the esm node output
shell.rm('-rf', 'pkg');
shell.exec('wasm-pack build --target experemintal-nodejs-module');
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Surely experemintal is a typo for experimental here

shell.mv('pkg', 'pkg.node.esm');
shell.rm('pkg.node/{LICENSE,package.json,README.md,.gitignore}');

// Create the web output
shell.rm('-rf', 'pkg');
shell.exec('wasm-pack build --target web');
Expand Down
2 changes: 2 additions & 0 deletions index.node.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import init, * as brotliWasm from "./pkg.node.esm/brotli_wasm.js";
export default init().then(() => brotliWasm);
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
"exports": {
".": {
"types": "./index.d.ts",
"import": "./index.web.js",
"node": {
"import": "./index.node.mjs",
"require": "./index.node.js"
},
"browser": "./index.browser.js",
"require": "./index.node.js",
"default": "./index.web.js"
Expand All @@ -17,9 +20,11 @@
"sideEffects": false,
"files": [
"pkg.node",
"pkg.node.esm",
"pkg.bundler",
"pkg.web",
"index.node.js",
"index.node.mjs",
"index.browser.js",
"index.web.js",
"index.d.ts"
Expand Down
Loading