From c7ff551d869b68d2fa083825e0f9ffcff6183bbc Mon Sep 17 00:00:00 2001 From: Raphael Date: Mon, 27 Nov 2023 16:50:03 +0100 Subject: [PATCH] fix conditional import for production server --- scripts/server-frontend-dev.js | 32 ++++++++------------------------ scripts/server.js | 10 +++++----- 2 files changed, 13 insertions(+), 29 deletions(-) diff --git a/scripts/server-frontend-dev.js b/scripts/server-frontend-dev.js index 2fa7788..30544b3 100644 --- a/scripts/server-frontend-dev.js +++ b/scripts/server-frontend-dev.js @@ -1,14 +1,6 @@ import webpack from "webpack"; import WebpackDevServer from "webpack-dev-server"; import config from "../config/webpack.dev.js"; -import { getArgs } from "./utils.js"; - -const args = getArgs(); - -if (typeof args.mode === "undefined") { - // default to production mode - args.mode = "production"; -} const devServerConfig = { hot: true, @@ -23,21 +15,13 @@ const devServerConfig = { }, }; -let startFrontendDevServer = function() {} +export default function then(port, resolve) { + new WebpackDevServer(webpack(config), devServerConfig).start(port, (err) => { + if (err) { + console.log(err); + } -if (args.mode === "production") { - console.log("Not loading webpack-dev-server because of production mode!"); -} else { - startFrontendDevServer = function(port) { - new WebpackDevServer(webpack(config), devServerConfig).start(port, (err) => { - if (err) { - console.log(err); - } - - console.log("Listening on port " + port); - }); - } + console.log("Listening on port " + port); + }); + resolve(1); } - - -export default startFrontendDevServer; \ No newline at end of file diff --git a/scripts/server.js b/scripts/server.js index c8ed7d0..d526cd9 100644 --- a/scripts/server.js +++ b/scripts/server.js @@ -1,5 +1,4 @@ import { getArgs } from "./utils.js"; -import startFrontendDevServer from "./server-frontend-dev.js"; import startBackendServer from "./server-backend.js"; const SERVER_MODES = { @@ -22,10 +21,11 @@ const server_mode = args.mode === "production" ? SERVER_MODES.PRODUCTION : SERVE if (server_mode === SERVER_MODES.DEVELOPMENT) { console.info("Starting server in development mode."); - startFrontendDevServer(8080); - // this time, it's the frontend server that is on port 8080 - // requests for the backend will be proxied to prevent cross origins errors - startBackendServer(3000); + import("./server-frontend-dev.js").then(function () { + // this time, it's the frontend server that is on port 8080 + // requests for the backend will be proxied to prevent cross origins errors + startBackendServer(3000); + }); } else { console.info("Starting server in production mode."); startBackendServer(process.env.PORT || 8080);