{"id":16278598,"url":"https://github.com/sigoden/wasm-pkg-build","last_synced_at":"2025-06-26T07:31:53.453Z","repository":{"id":58924006,"uuid":"532752541","full_name":"sigoden/wasm-pkg-build","owner":"sigoden","description":"Effortlessly create npm packages from Rust wasm crates.","archived":false,"fork":false,"pushed_at":"2024-06-28T15:01:41.000Z","size":178,"stargazers_count":12,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-06-05T07:16:01.801Z","etag":null,"topics":["crate","npm-package","wasm","wasm-bindgen","wasm-pack"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sigoden.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-09-05T05:13:26.000Z","updated_at":"2025-05-28T16:36:32.000Z","dependencies_parsed_at":"2024-04-14T12:27:06.915Z","dependency_job_id":"e5a4d8f7-a776-4564-88a7-d7efd44dbb95","html_url":"https://github.com/sigoden/wasm-pkg-build","commit_stats":{"total_commits":34,"total_committers":1,"mean_commits":34.0,"dds":0.0,"last_synced_commit":"6798c91760b25ca57a8341c40cd5e8f54dfbd617"},"previous_names":["sigoden/wasm-pack-utils"],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/sigoden/wasm-pkg-build","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sigoden%2Fwasm-pkg-build","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sigoden%2Fwasm-pkg-build/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sigoden%2Fwasm-pkg-build/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sigoden%2Fwasm-pkg-build/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sigoden","download_url":"https://codeload.github.com/sigoden/wasm-pkg-build/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sigoden%2Fwasm-pkg-build/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262022143,"owners_count":23246266,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["crate","npm-package","wasm","wasm-bindgen","wasm-pack"],"created_at":"2024-10-10T18:59:07.071Z","updated_at":"2025-06-26T07:31:53.405Z","avatar_url":"https://github.com/sigoden.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# wasm-pkg-build\n\n[![CI](https://github.com/sigoden/wasm-pkg-build/actions/workflows/ci.yaml/badge.svg)](https://github.com/sigoden/wasm-pkg-build/actions/workflows/ci.yaml)\n[![NPM Version](https://img.shields.io/npm/v/wasm-pkg-build)](https://www.npmjs.com/package/wasm-pkg-build)\n\nEffortlessly create npm packages from Rust wasm crates.\n\n## Key Features:\n\n* **Effortless Package Creation:** Automatically compiles your Rust code, generates JavaScript bindings, and optimizes WASM files. \n* **Multiple Module Types:** Supports various JS module types (CJS, ESM) and WASM loading methods (sync, async) in a single package.\n* **Tool Management:** No need to worry about wasm-bindgen or wasm-opt tools – it handles everything for you!\n\n## Installation\n\n```bash\nnpm i -D wasm-pkg-build\nyarn add --dev wasm-pkg-build\n```\n\n## Understanding Module Types\n\nJavaScript utilizes CommonJS (CJS) and ECMAScript modules (ESM). WASM can be initialized synchronously or asynchronously.\n\n**wasm-pkg-build** provides various module types to accommodate these differences:\n\n| module      | sync | inline | target       |\n| ----------- | ---- | ------ | ------------ |\n| esm-bundler | -    | ✗      | -            |\n| cjs         | ✓    | ✗      | node         |\n| cjs-inline  | ✓    | ✓      | node         |\n| esm         | ✗    | ✗      | web          |\n| esm-inline  | ✗    | ✓      | web          |\n| esm-sync    | ✓    | ✓      | worker, node |\n\n`-inline` means the WASM binary is embedded within the JS file.\n\n## Basic Usage Example\n\nLet's say you have a Rust crate called `test_crate` with a function `greet`:\n\n```rust\nuse wasm_bindgen::prelude::*;\n\n#[wasm_bindgen]\npub fn reverse(input: \u0026str) -\u003e String {\n  return input.chars().rev().collect();\n}\n```\n\nTo build a package with all module types:\n\n```bash\nwasm-pkg-build test_crate --modules 'cjs,cjs-inline,esm,esm-inline,esm-sync' \n```\n\nThis generates files in the `pkg` directory (by default) for each module type:\n\n```\npackage.json\ntest_crate.d.ts            \ntest_crate.js              # cjs\ntest_crate_bg.js           # esm-bundler\ntest_crate_bg.wasm         \ntest_crate_bg.wasm.d.ts\ntest_crate_inline.js       # cjs-inline\ntest_crate_web.js          # esm\ntest_crate_web_inline.js   # esm-inline\ntest_crate_worker.js       # esm-sync\n```\n\n## Importing Modules\n\nHere's how you would import and use the generated modules in JavaScript:\n\n* **CJS/CJS-inline:**\n\n```js\nconst { reverse } = require(\"./pkg/test_crate.js\"); // or ./pkg/test_crate_inline.js for inline\nconsole.log(reverse(\"test_crate\"));\n```\n\n* **ESM/ESM-inline:**\n\n```js\nimport init from \"./pkg/test_crate_web.js\"; // or ./pkg/test_crate_web_inline.js for inline\ninit().then(mod =\u003e {\n  console.log(mod.reverse(\"test_crate_web\"));\n})\n```\n\n* **ESM-sync:**\n\n```js\nimport { reverse } from \"./pkg/test_crate_worker.js\";\nconsole.log(reverse(\"test_crate\"));\n```\n\n## Command-Line Usage\n\nThe command-line interface is straightforward and offers several options to customize your build:\n\n```\nUsage: wasm-pkg-build [options] [crate]\n\nGenerate wasm js modules from a wasm crate\n\nArguments:\n  crate                       path to a wasm crate [default: \u003ccwd\u003e]\n\nOptions:\n  --out-dir \u003cdir\u003e             output directory relative to crate [default: \u003ccrate\u003e/pkg]\n  --out-name \u003cvar\u003e            set a custom output filename (Without extension) [default: \u003ccrate_name\u003e]\n  --verbose                   whether to display extra compilation information in the console\n  --debug                     whether to build in debug mode or release mode\n  --cargo-args \u003cargs\u003e         extra args to pass to 'cargo build'\n  --wasm-bindgen-args \u003cargs\u003e  extra args to pass to 'wasm-bindgen'\n  --wasm-opt-args \u003cargs\u003e      extra args to pass to 'wasm-opt'\n  --wasm-opt-version \u003cver\u003e    specify the version of 'wasm-opt' [default: latest]\n  --modules \u003cmodules\u003e         generate additional js modules(cjs,cjs-inline,esm,esm-inline,esm-sync) [default: 'cjs,esm']\n  -V, --version               output the version number\n  -h, --help                  display help for command\n```\n\n## License\n\nThe project is under the MIT License, Refer to the [LICENSE](https://github.com/sigoden/wasm-pkg-build/blob/main/LICENSE) file for detailed information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsigoden%2Fwasm-pkg-build","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsigoden%2Fwasm-pkg-build","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsigoden%2Fwasm-pkg-build/lists"}