Path: blob/main/web/cowasm.org/webpack.config.js
2116 views
/*1This is a minimal webpack config file for using python-wasm in a frontend2Javascript project that uses WebPack 5 (and Typescript). There are two3small things that you must:45- The NodePolyfillPlugin is needed because python-wasm6uses memfs, which requires several polyfilled libraries.78- The wasm and zip asset/resource rules are needed so python-wasm9can import the python wasm binary and zip filesystem.1011*/1213const { resolve } = require("path");14const HtmlWebpackPlugin = require("html-webpack-plugin");15const NodePolyfillPlugin = require("node-polyfill-webpack-plugin");16const mode =17process.env.NODE_ENV == "production" ? "production" : "development";1819module.exports = {20mode,21entry: "./src/index.ts",22devtool: "inline-source-map",23output: {24filename: "[name].bundle.js",25path: resolve(__dirname, "dist"),26clean: true,27filename:28mode == "production" ? "[name]-[chunkhash].js" : "[id]-[chunkhash].js",29chunkFilename:30mode == "production" ? "[chunkhash].js" : "[id]-[chunkhash].js",31hashFunction: "sha256",32},33plugins: [34new NodePolyfillPlugin() /* required for python-wasm */,35new HtmlWebpackPlugin({36title: "CoWasm: Collaborative WebAssembly for Servers and Browsers",37}),38],39module: {40rules: [41{42test: /\.wasm$|\.zip$|\.tar.xz$|\.ico$/ /* required for python-wasm */,43type: "asset/resource",44},45{46test: /\.tsx?$/,47use: "ts-loader",48exclude: /node_modules/,49},50{51test: /\.css$/i,52use: ["style-loader", "css-loader"],53},54],55},56resolve: {57extensions: [".tsx", ".ts", ".js"],58},59devServer: {60headers: {61"Cross-Origin-Opener-Policy": "same-origin",62"Cross-Origin-Embedder-Policy": "require-corp",63},64},65};6667// Refactor same code in terminal and webpack packages.68if (process.env.COCALC_PROJECT_ID && process.env.NODE_ENV != "production") {69const port = 8080;70const basePath = `/${process.env.COCALC_PROJECT_ID}/port/${port}/`;71// Working in a cocalc project, so do a bit more to support the base path under.72module.exports.output.publicPath = basePath;73module.exports.devServer.port = port;74module.exports.devServer.allowedHosts = "all";75module.exports.devServer.host = "0.0.0.0";76module.exports.devServer.client = {77webSocketURL: `auto://cocalc.com${basePath}ws`,78};79console.log(`https://cocalc.com${basePath}\n`);80}818283