fix conditional import for production server
This commit is contained in:
parent
7e2c08bdd6
commit
c7ff551d86
@ -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,12 +15,7 @@ const devServerConfig = {
|
||||
},
|
||||
};
|
||||
|
||||
let startFrontendDevServer = function() {}
|
||||
|
||||
if (args.mode === "production") {
|
||||
console.log("Not loading webpack-dev-server because of production mode!");
|
||||
} else {
|
||||
startFrontendDevServer = function(port) {
|
||||
export default function then(port, resolve) {
|
||||
new WebpackDevServer(webpack(config), devServerConfig).start(port, (err) => {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
@ -36,8 +23,5 @@ if (args.mode === "production") {
|
||||
|
||||
console.log("Listening on port " + port);
|
||||
});
|
||||
resolve(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export default startFrontendDevServer;
|
@ -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);
|
||||
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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user