Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/wapython
Path: blob/main/desktop/electron/webpack.config.js
1067 views
1
/*
2
This is a minimal webpack config file for using python-wasm in a frontend
3
Javascript project that uses WebPack 5 (and Typescript). There are two
4
small things that you must:
5
6
- The NodePolyfillPlugin is needed because python-wasm
7
uses memfs, which requires several polyfilled libraries.
8
9
- The wasm and zip asset/resource rules are needed so python-wasm
10
can import the python wasm binary and zip filesystem.
11
12
*/
13
14
const { resolve } = require("path");
15
const HtmlWebpackPlugin = require("html-webpack-plugin");
16
const NodePolyfillPlugin = require("node-polyfill-webpack-plugin");
17
18
module.exports = {
19
mode: process.env.NODE_ENV == "production" ? "production" : "development",
20
entry: "./src/renderer.ts",
21
devtool: "inline-source-map",
22
output: {
23
filename: "[name].bundle.js",
24
path: resolve(__dirname, "dist/renderer"),
25
clean: true,
26
},
27
plugins: [
28
new NodePolyfillPlugin() /* required for python-wasm */,
29
new HtmlWebpackPlugin({
30
title: "CoWasm Desktop",
31
}),
32
],
33
module: {
34
rules: [
35
{
36
test: /\.wasm$|\.zip$|\.tar.xz$/ /* required for python-wasm */,
37
type: "asset/resource",
38
},
39
{
40
test: /\.tsx?$/,
41
use: "ts-loader",
42
exclude: /node_modules/,
43
},
44
{
45
test: /\.css$/i,
46
use: ["style-loader", "css-loader"],
47
},
48
],
49
},
50
resolve: {
51
extensions: [".tsx", ".ts", ".js"],
52
},
53
};
54
55