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