{"id":21188405,"url":"https://github.com/drsensor/binaryen-loader","last_synced_at":"2025-07-10T02:31:27.592Z","repository":{"id":46945464,"uuid":"136369598","full_name":"DrSensor/binaryen-loader","owner":"DrSensor","description":"webpack loader for Binaryen","archived":false,"fork":false,"pushed_at":"2023-02-27T23:52:21.000Z","size":379,"stargazers_count":3,"open_issues_count":32,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-13T18:18:38.989Z","etag":null,"topics":["my-study","webassembly","webpack-loader"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/DrSensor.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null}},"created_at":"2018-06-06T18:22:34.000Z","updated_at":"2022-12-16T19:59:03.000Z","dependencies_parsed_at":"2023-01-29T15:45:34.274Z","dependency_job_id":null,"html_url":"https://github.com/DrSensor/binaryen-loader","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DrSensor%2Fbinaryen-loader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DrSensor%2Fbinaryen-loader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DrSensor%2Fbinaryen-loader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DrSensor%2Fbinaryen-loader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DrSensor","download_url":"https://codeload.github.com/DrSensor/binaryen-loader/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225613142,"owners_count":17496773,"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":["my-study","webassembly","webpack-loader"],"created_at":"2024-11-20T18:44:40.297Z","updated_at":"2024-11-20T18:44:40.832Z","avatar_url":"https://github.com/DrSensor.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n  \u003ca href=\"https://github.com/WebAssembly/binaryen\"\u003e\n    \u003cimg width=\"200\" height=\"200\" alt=\"binaryen logo\" src=\"\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/webpack/webpack\"\u003e\n    \u003cimg width=\"200\" height=\"200\" alt=\"webpack logo\" src=\"https://webpack.js.org/assets/icon-square-big.svg\"\u003e\n  \u003c/a\u003e\n\u003c/div\u003e\n\n[![npm][npm]][npm-url]\n[![node][node]][node-url]\n[![deps][deps]][deps-url]\n[![tests][tests]][tests-url]\n[![size][size]][size-url]\n\n# binaryen-loader\n\nA loader to reduce wasm code size based on [Binaryen][].\n\n## Requirements\n\nThis module requires a minimum of Node v6.9.0 and Webpack v4.0.0.\n\n## Getting Started\n\nTo begin, you'll need to install `binaryen-loader`:\n\n```console\n$ npm install binaryen-loader --save-dev\n```\n\nThen add the loader to your `webpack` config. For example:\n\n**file.wasm**\n```js\nimport file from 'file.wasm';\n```\n\n**webpack.config.js**\n```js\nmodule.exports = {\n  module: {\n    rules: [\n      {\n        test: /\\.wasm$/,\n        use: [\n          {\n            loader: `binaryen-loader`,\n            options: {...options}\n          }\n        ]\n      }\n    ]\n  }\n}\n```\n\nAnd run `webpack` via your preferred method.\n\n## Options\nThe options in binaryen-loader correspond to [module-optimization](https://github.com/AssemblyScript/binaryen.js/#module-optimization) section in [binaryen.js][].\n\n### `debug`\n\n- Type: `Boolean`\n- Default: `false`\n- Correspond to: `setDebugInfo`\n\nEnables or disables debug information in emitted binaries.\n\n```js\n// in your webpack.config.js\n{\n  loader: `binaryen-loader`,\n  options: {\n    debug: true\n  }\n}\n```\n\n### `optimization.level`\n\n- Type: `Integer`\n- Default: `2`\n- Expected value: from `0` to `2`\n- Correspond to: `setOptimizeLevel`\n\nSets the optimization level that correspond to flag `-O0`, `-O1`, `-O2`, etc.\n\n```js\n// in your webpack.config.js\n{\n  loader: `binaryen-loader`,\n  options: {\n    optimization: {\n      level: 0\n    }\n  }\n}\n```\n\n### `optimization.shrinkLevel`\n\n- Type: `Integer`\n- Default: `1`\n- Expected value: from `0` to `2`\n- Correspond to: `setShrinkLevel`\n\nSets the shrink level that correspond to flag `-O0`, `-Os`, `-Oz`.\n\n```js\n// in your webpack.config.js\n{\n  loader: `binaryen-loader`,\n  options: {\n    optimization: {\n      shrinkLevel: 2\n    }\n  }\n}\n```\n\n### `transformation.passes`\n\n- Type: `String|Array\u003cString\u003e`\n- Default: see [`DefaultGlobalOptimization` in pass.cpp](https://github.com/WebAssembly/binaryen/blob/master/src/passes/pass.cpp#L190-L204)\n- Expected value: see [`PassRegistry::registerPasses` in pass.cpp](https://github.com/WebAssembly/binaryen/blob/master/src/passes/pass.cpp#L67-L126)\n- Correspond to: `runPasses`\n\nRuns the specified passes on the module.\n\n```js\n// in your webpack.config.js\n{\n  loader: `binaryen-loader`,\n  options: {\n    transformation: {\n      passes: 'post-emscripten'\n    }\n  }\n}\n```\nor\n```js\n// in your webpack.config.js\n{\n  loader: `binaryen-loader`,\n  options: {\n    transformation: {\n      passes: [\n        'post-emscripten',\n        'remove-memory'\n      ]\n    }\n  }\n}\n```\n\n### `transformation.function` (still experimental)\n\n- Type: `String`\n- Default: `null`\n- Expected value: any valid function name exported from `.wasm` file\n- Correspond to: `optimizeFunction` (if passes undefined) or `runPassesOnFunction` (if passes defined)\n\nOptimizes a single function using defined and/or default passes.\n\n```js\n// in your webpack.config.js\n{\n  loader: `binaryen-loader`,\n  options: {\n    transformation: {\n      function: 'add'\n    }\n  }\n}\n```\n\n## Examples\n\nThe following examples show how to use `binaryen-loader` chained with `wasm-loader`.\n\n![chain illustration](./asset/example_1.svg)\n\n**webpack.config.js**\n```js\nmodule.exports = {\n  module: {\n    rules: [{\n      test: /\\.wasm$/,\n      use: [{\n        loader: 'wasm-loader'\n      }, {\n        loader: `binaryen-loader`,\n        options: {\n          transformation: {\n            passes: [\n              'post-emscripten',\n              'remove-memory'\n            ]\n          }\n        }\n      }]\n    }]\n  }\n}\n```\n\n**arithmatic.wasm** (if converted into `.wat`)\n```wat\n(module\n  (type $t0 (func (param i32 i32) (result i32)))\n  (func $add (export \"add\") (type $t0) (param $0 i32) (param $1 i32) (result i32)\n    get_local $0\n    get_local $1\n    i32.add)\n  (memory $memory (export \"memory\") 1))\n```\n\n**implementation.js**\n```js\nimport loadArithmatic from 'arithmatic.wasm';\n\nloadArithmatic.then(wasm =\u003e\n  const { add } = wasm.instance.exports;\n  console.log(add(1, 2)); // 3\n);\n```\n\n## Contributing\n\nPlease take a moment to read our contributing guidelines if you haven't yet done so.\n\n#### [CONTRIBUTING](./.github/CONTRIBUTING.md)\n\n## License\n\n#### [MIT](./LICENSE)\n\n---\n\u003csup\u003eThis project generated and modified based on [webpack-defaults](https://github.com/webpack-contrib/webpack-defaults).\nDefault Contribution guideline, Issue and PR template are intentionally left behind, not edited until there is some feedback about that 🙂\u003c/sup\u003e\n\n[Binaryen]: https://github.com/WebAssembly/binaryen\n[binaryen.js]: https://github.com/AssemblyScript/binaryen.js\n\n[npm]: https://img.shields.io/npm/v/binaryen-loader.svg\n[npm-url]: https://npmjs.com/package/binaryen-loader\n\n[node]: https://img.shields.io/node/v/binaryen-loader.svg\n[node-url]: https://nodejs.org\n\n[deps]: https://david-dm.org/DrSensor/binaryen-loader.svg\n[deps-url]: https://david-dm.org/DrSensor/binaryen-loader\n\n[tests]: \thttps://img.shields.io/circleci/project/github/DrSensor/binaryen-loader.svg\n[tests-url]: https://circleci.com/gh/DrSensor/binaryen-loader\n\n[cover]: https://codecov.io/gh/DrSensor/binaryen-loader/branch/master/graph/badge.svg\n[cover-url]: https://codecov.io/gh/DrSensor/binaryen-loader\n\n[size]: https://packagephobia.now.sh/badge?p=binaryen-loader\n[size-url]: https://packagephobia.now.sh/result?p=binaryen-loader\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrsensor%2Fbinaryen-loader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdrsensor%2Fbinaryen-loader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrsensor%2Fbinaryen-loader/lists"}