Files
thelounge/server/plugins/dev-server.ts
Max Leiter 769c9614b3 chore: bump some dev deps (mainly webpack) (#5042)
Closes some renovate PRs like
https://github.com/thelounge/thelounge/pull/5024 and should improve dev
perf.

It might be better to merge this instead:
https://github.com/thelounge/thelounge/pull/5001

---------

Co-authored-by: Tiago de Paula <tiagodepalves@gmail.com>
2026-04-11 14:28:18 -07:00

48 lines
1.2 KiB
TypeScript

import webpackDevMiddleware from "webpack-dev-middleware";
import webpackHotMiddleware from "webpack-hot-middleware";
import express from "express";
import log from "../log";
import webpack from "webpack";
import config from "../../webpack.config";
export default (app: express.Application) => {
log.debug("Starting server in development mode");
const webpackConfig = config(undefined, {mode: "production"});
if (
!webpackConfig ||
!webpackConfig.plugins?.length ||
!webpackConfig.entry ||
!webpackConfig.entry["js/bundle.js"]
) {
throw new Error("No valid production webpack config found");
}
webpackConfig.plugins.push(new webpack.HotModuleReplacementPlugin());
webpackConfig.entry["js/bundle.js"].push(
"webpack-hot-middleware/client?path=storage/__webpack_hmr"
);
const compiler = webpack(webpackConfig);
if (!compiler) {
throw new Error("Webpack failed to create a compiler");
}
app.use(
// eslint-disable-next-line @typescript-eslint/no-misused-promises
webpackDevMiddleware(compiler, {
index: "/",
publicPath: webpackConfig.output?.publicPath,
})
).use(
// TODO: Fix compiler type
webpackHotMiddleware(compiler as any, {
path: "/storage/__webpack_hmr",
})
);
};