const { resolve } = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const NodePolyfillPlugin = require("node-polyfill-webpack-plugin");
const mode =
process.env.NODE_ENV == "production" ? "production" : "development";
module.exports = {
mode,
entry: "./src/index.ts",
devtool: "inline-source-map",
output: {
filename: "[name].bundle.js",
path: resolve(__dirname, "dist"),
clean: true,
filename:
mode == "production" ? "[name]-[chunkhash].js" : "[id]-[chunkhash].js",
chunkFilename:
mode == "production" ? "[chunkhash].js" : "[id]-[chunkhash].js",
hashFunction: "sha256",
},
plugins: [
new NodePolyfillPlugin() ,
new HtmlWebpackPlugin({
title: "CoWasm: Collaborative WebAssembly for Servers and Browsers",
}),
],
module: {
rules: [
{
test: /\.wasm$|\.zip$|\.tar.xz$|\.ico$/ ,
type: "asset/resource",
},
{
test: /\.tsx?$/,
use: "ts-loader",
exclude: /node_modules/,
},
{
test: /\.css$/i,
use: ["style-loader", "css-loader"],
},
],
},
resolve: {
extensions: [".tsx", ".ts", ".js"],
},
devServer: {
headers: {
"Cross-Origin-Opener-Policy": "same-origin",
"Cross-Origin-Embedder-Policy": "require-corp",
},
},
};
if (process.env.COCALC_PROJECT_ID && process.env.NODE_ENV != "production") {
const port = 8080;
const basePath = `/${process.env.COCALC_PROJECT_ID}/port/${port}/`;
module.exports.output.publicPath = basePath;
module.exports.devServer.port = port;
module.exports.devServer.allowedHosts = "all";
module.exports.devServer.host = "0.0.0.0";
module.exports.devServer.client = {
webSocketURL: `auto://cocalc.com${basePath}ws`,
};
console.log(`https://cocalc.com${basePath}\n`);
}