Skip to content

wasm-tool/emscripten

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@wasm-tool/emscripten

Emscripten loader for webpack

Installation

npm i -D @wasm-tool/emscripten

Usage: webpack

Add the loader and mock the fs module in your webpack configuration:

module.exports = {
  // ...
  module: {
    rules: [
      {
        test: /\.c$/,
        type: "javascript/auto",
        loader: "@wasm-tool/emscripten"
      }
    ]
  },
  node: {
    fs: "empty"
  },
  // ...
};

We need to set the type to JavaScript to bypass webpack's wasm support (as a workaround, for now). Which will also prevent the loading to work correclty in non-web environements.

You can then directly import c files:

import("./add.c").then(exports => ...);

emcc must be available in your $PATH, see http://kripken.github.io/emscripten-site/docs/getting_started/downloads.html.