Path: blob/main/web/browser/webpack-min.config.js
1391 views
/*1This is an attempt to make the bundle2smaller by enabling measuring, dangerously removing some node3polyfills, etc. It doesn't help much.45The Javascript download is about about 1.8MB gziped, and with these6optimizations it gets it down to about 1.6MB.78For comparison, emscripten's Javascript shipped with pyodide seems9to be on the order of 0.3MB.1011The difference is that we use a bunch of standard modules, e.g., memfs,12unionfs, modules from node.js for buffers, process, streams, events, etc.13This is all very nice, documented, modern, and fits into a big ecosystem.14But it is also 1MB more Javascript. It's a tradeoff.15*/1617const { resolve } = require("path");18const HtmlWebpackPlugin = require("html-webpack-plugin");19const NodePolyfillPlugin = require("node-polyfill-webpack-plugin");20const { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer");2122const NODE_MODULES = [23"Buffer",24"buffer",25"events",26"path",27"process",28"stream",29"util",30];3132module.exports = {33mode: process.env.NODE_ENV == "production" ? "production" : "development",34entry: "./src/index.ts",35devtool: "inline-source-map",36output: {37filename: "[name].bundle.js",38path: resolve(__dirname, "dist"),39clean: true,40},41plugins: [42new NodePolyfillPlugin({43includeAliases: NODE_MODULES,44}) /* required for python-wasm */,45new HtmlWebpackPlugin({46title: "Web Python Examples",47}),48new BundleAnalyzerPlugin({49analyzerMode: "static",50reportFilename: "measure.html",51}),52],53module: {54rules: [55{56test: /\.wasm$|\.zip$/ /* required for python-wasm */,57type: "asset/resource",58},59{60test: /\.tsx?$/,61use: "ts-loader",62exclude: /node_modules/,63},64],65},66resolve: {67alias: { assert: false, url: false },68extensions: [".tsx", ".ts", ".js"],69},70devServer: {71headers: {72"Cross-Origin-Opener-Policy": "same-origin",73"Cross-Origin-Embedder-Policy": "require-corp",74},75},76};7778// Refactor same code in terminal and webpack packages.79if (process.env.COCALC_PROJECT_ID && process.env.NODE_ENV != "production") {80const port = 8080;81const basePath = `/${process.env.COCALC_PROJECT_ID}/port/${port}/`;82// Working in a cocalc project, so do a bit more to support the base path under.83module.exports.output.publicPath = basePath;84module.exports.devServer.port = port;85module.exports.devServer.allowedHosts = "all";86module.exports.devServer.host = "0.0.0.0";87module.exports.devServer.client = {88webSocketURL: `auto://cocalc.com${basePath}ws`,89};90console.log(`https://cocalc.com${basePath}\n`);91}929394