1.0.1 • Published 3 years ago
@wapython/webpack v1.0.1
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 serveThen visit the URL that it outputs, which is probably http://localhost:8080