thelounge/server/plugins/dev-server.ts
Tiago de Paula ca79426e6e
chore(deps): update Webpack to 5.105
It's possible for webpack to return `null` on errors, which wasn't
part of their TypeScript API until 5.101.0 (webpack/webpack#19711).

Updated workaround for socket.io libraries, which are implemented in
ESM now. This also specify the preferred import conditions to avoid
picking up debug files (see socketio/socket.io@7594aa4).
2026-02-11 12:14:12 -03:00

46 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(
webpackHotMiddleware(compiler, {
path: "/storage/__webpack_hmr",
})
);
};