Create a bundle for browsers that includes the Wasm code?

Open
#408 11 comments 7 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
javascript, wasm, webpack

Research direction

Start with the proposed webpack.config.js and the browser setup using lib/mappings.wasm, then inspect the TypeScript declaration file for SourceMapConsumer.initialize(). Define the browser bundle and Node.js behavior, and update the declarations if appropriate; done means consumers can use the Wasm implementation without exposing its setup details.

Written by the indexing model from the issue text.

Description

feat

Suggestion: source-map would be easier to use if it completely hid the fact that it internally uses Wasm.

  • For browsers, you can do that by distributing a bundle, as shown below.
  • For Node.js, this should be even simpler.

webpack.config.js:

const path = require('path');

module.exports = {
  // ···
  module: {
    rules: [
      {
        test: /\.wasm$/,
        type: 'javascript/auto',
        loader: 'arraybuffer-loader', // installed via npm
      },    
    ],
  },
};

Setup code (when used outside the library):

import arrayBuffer from 'source-map/lib/mappings.wasm';
SourceMapConsumer.initialize({
  'lib/mappings.wasm': arrayBuffer,
});

AFAICT, .initialize() is not in the .d.ts file. Maybe add it?

Dominant language
JavaScript
Stars
3.7k
Forks
370
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from mozilla/source-map

All issues in mozilla/source-map

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.