@wapython/webpack

1.0.1 • Public • Published

Using python-wasm with webpack

You can use python-wasm with webpack5. There are two things you may have to modify in your webpack configuration. See webpack.config.js, in particular:

  • The NodePolyfillPlugin is needed because python-wasm uses memfs, which requires several polyfilled libraries.

  • The wasm and zip asset/resource rules are needed so python-wasm can import the python wasm binary and zip filesystem.

Thus your webpack.config.js has to include this:

const NodePolyfillPlugin = require("node-polyfill-webpack-plugin");

module.exports = {
  plugins: [
    new NodePolyfillPlugin(),
    // ...
  ],
  module: {
    rules: [
      {
        test: /\.wasm$|\.zip$/,
        type: "asset/resource",
      },
      //...
    ],
  },
};

Once you do that, you can just put

const python = require("python-wasm");

or (for Typescript)

import python from "python-wasm";

in your code and use the python object, as illustrated here in src/index.ts.

Trying the demo in your browser

git clone https://github.com/sagemathinc/python-wasm
cd python-wasm/packages/webpack
npm ci
npm run serve

Then visit the URL that it outputs, which is probably http://localhost:8080

Readme

Keywords

Package Sidebar

Install

npm i @wapython/webpack

Weekly Downloads

2

Version

1.0.1

License

BSD-3-Clause

Unpacked Size

5.16 kB

Total Files

6

Last publish

Collaborators

  • wstein