{"id":13829493,"url":"https://github.com/ballercat/wasm-loader","last_synced_at":"2025-07-09T10:30:34.565Z","repository":{"id":65419339,"uuid":"85236827","full_name":"ballercat/wasm-loader","owner":"ballercat","description":":sparkles: WASM webpack loader","archived":true,"fork":false,"pushed_at":"2021-10-16T18:04:50.000Z","size":27,"stargazers_count":643,"open_issues_count":0,"forks_count":35,"subscribers_count":15,"default_branch":"master","last_synced_at":"2025-06-12T08:04:15.964Z","etag":null,"topics":["javascript","loader","wasm","webassembly","webpack","webpack-loader"],"latest_commit_sha":null,"homepage":"","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/ballercat.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-03-16T20:03:38.000Z","updated_at":"2025-06-04T11:36:55.000Z","dependencies_parsed_at":"2023-01-22T18:15:31.015Z","dependency_job_id":null,"html_url":"https://github.com/ballercat/wasm-loader","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ballercat/wasm-loader","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ballercat%2Fwasm-loader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ballercat%2Fwasm-loader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ballercat%2Fwasm-loader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ballercat%2Fwasm-loader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ballercat","download_url":"https://codeload.github.com/ballercat/wasm-loader/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ballercat%2Fwasm-loader/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259940814,"owners_count":22935289,"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":["javascript","loader","wasm","webassembly","webpack","webpack-loader"],"created_at":"2024-08-04T10:00:37.644Z","updated_at":"2025-07-09T10:30:34.271Z","avatar_url":"https://github.com/ballercat.png","language":"JavaScript","readme":"[![Build Status](https://travis-ci.org/ballercat/wasm-loader.svg?branch=master)](https://travis-ci.org/ballercat/wasm-loader)\n[![Package Quality](http://npm.packagequality.com/shield/wasm-loader.svg)](http://packagequality.com/#?package=wasm-loader)\n\n# ⚠️ ⚠️ This loader is DEPRECATED. Use NATIVE Webpack 5 Support for WebAssembly as described [here](https://webpack.js.org/configuration/experiments/) or follow a tiny demo example [here](https://github.com/ballercat/minimal-webpack5-wasm-demo). ⚠️ ⚠️\n\n# WASM Binary Module loader for Webpack\n\nA simple `.wasm` binary file loader for Webpack. Import your wasm modules directly into your bundle as Constructors which return `WebAssembly.Instance`. This avoids the need to use fetch and parse for your wasm files. Imported wasm files\nare converted to Uint8Arrays and become part of the full JS bundle!\n\n## Install\n\nInstall package:\n`npm install --save wasm-loader`\n\n# Usage\n\nEdit webpack.config.js:\n```\n  loaders: [\n    {\n      test: /\\.wasm$/,\n      loaders: ['wasm-loader']\n    }\n  ]\n```\n\n## Optimizations\n\n### Dead code elemination\n\nThis is an experimental feature and thus not activated by default.\n\nYou can activate it by passing `dce=1` to the import and by specifying manually (for now) the exported elements you use, like the following example:\n\n```js\nimport createInstance from \"./add.wasm?dce=1\u0026add\u0026test\"\n\ncreateInstance()\n.then(m =\u003e {\n  console.log(m.instance.exports.add(1, 2));\n  console.log(m.instance.exports.test());\n});\n```\n\nEverything else in the `add.wasm` binary will be removed.\n\n## Include wasm from your code\n\nGrab your pre-built wasm file. For demo purposes we will use the excellent [WasmExplorer](https://mbebenita.github.io/WasmExplorer/).\n`factorial.wasm` file exports a function returning a factorial for a given number.\n\nWith the loader you can import this file directy\n```javascript\nimport makeFactorial from 'wasm/factorial';\n```\n\nThe default export from the loader is a function returning native `Promise`.  The promise resolves to a  [WebAssembly.Instance](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance).\n\n```javascript\nmakeFactorial().then(instance =\u003e {\n  // What is with the weird exports._Z4facti function?\n  // This is how the function name is encoded by the C++ to wasm compiler\n  const factorial = instance.exports._Z4facti;\n\n  console.log(factorial(1)); // 1\n  console.log(factorial(2)); // 2\n  console.log(factorial(3)); // 6\n});\n```\n\n`deps` can be passed in to\noverride defaults. For example\n\n```javascript\nmakeFactorial({\n  'global': {},\n  'env': {\n    'memory': new WebAssembly.Memory({initial: 100, limit: 1000}),\n    'table': new WebAssembly.Table({initial: 0, element: 'anyfunc'})\n  }\n}).then(instance =\u003e { /* code here */ });\n```\n\n*Default deps are:*\n```javascript\n{\n  'global': {},\n  'env': {\n    'memory': new Memory({initial: 10, limit: 100}),\n    'table': new Table({initial: 0, element: 'anyfunc'})\n  }\n}\n```\n\n## A note about default deps(importsObject)\n\nDefault `importsObject` is meant to be used for a very basic wasm module. Most likely it will not suffice for something not dead simple compiled with emscripten. This is intentional. Supply your own\nimports to match the requirements of your wasm module(s). Some options are compiling your source code into S-syntax(`.wast`) examining that output, checking the imports. Compile the s-syntax file with\n`asm2wasm` into the final wasm module.\n\n","funding_links":[],"categories":["Projects","Misc","JavaScript"],"sub_categories":["webpack"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fballercat%2Fwasm-loader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fballercat%2Fwasm-loader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fballercat%2Fwasm-loader/lists"}