feat(build): integrate webpack middleware

This commit is contained in:
Elian Doran
2024-12-14 10:05:38 +02:00
parent 3e710fbdf5
commit b3b8ae4a0e
3 changed files with 285 additions and 5 deletions

View File

@@ -4,6 +4,19 @@ import { fileURLToPath } from "url";
import express from "express";
import env from "../services/env.js";
import serveStatic from "serve-static";
import webpack from "webpack";
import webpackMiddleware from "webpack-dev-middleware";
const frontendCompiler = webpack({
mode: "development",
entry: {
setup: './src/public/app/setup.js',
mobile: './src/public/app/mobile.js',
desktop: './src/public/app/desktop.js',
},
devtool: 'source-map',
target: 'electron-renderer'
});
const persistentCacheStatic = (root: string, options?: serveStatic.ServeStaticOptions<express.Response<any, Record<string, any>>>) => {
if (!env.isDev()) {
@@ -17,7 +30,9 @@ const persistentCacheStatic = (root: string, options?: serveStatic.ServeStaticOp
function register(app: express.Application) {
const srcRoot = path.join(path.dirname(fileURLToPath(import.meta.url)), '..');
app.use(`/${assetPath}/app`, persistentCacheStatic(path.join(srcRoot, 'public/app')));
app.use(`/${assetPath}/app`, webpackMiddleware(frontendCompiler, {
}));
app.use(`/${assetPath}/app-dist`, persistentCacheStatic(path.join(srcRoot, 'public/app-dist')));
app.use(`/${assetPath}/fonts`, persistentCacheStatic(path.join(srcRoot, 'public/fonts')));
app.use(`/assets/vX/fonts`, express.static(path.join(srcRoot, 'public/fonts')));