fix conditional import for production server
This commit is contained in:
parent
7e2c08bdd6
commit
c7ff551d86
@ -1,14 +1,6 @@
|
|||||||
import webpack from "webpack";
|
import webpack from "webpack";
|
||||||
import WebpackDevServer from "webpack-dev-server";
|
import WebpackDevServer from "webpack-dev-server";
|
||||||
import config from "../config/webpack.dev.js";
|
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 = {
|
const devServerConfig = {
|
||||||
hot: true,
|
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("Listening on port " + port);
|
||||||
console.log("Not loading webpack-dev-server because of production mode!");
|
});
|
||||||
} else {
|
resolve(1);
|
||||||
startFrontendDevServer = function(port) {
|
|
||||||
new WebpackDevServer(webpack(config), devServerConfig).start(port, (err) => {
|
|
||||||
if (err) {
|
|
||||||
console.log(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log("Listening on port " + port);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export default startFrontendDevServer;
|
|
@ -1,5 +1,4 @@
|
|||||||
import { getArgs } from "./utils.js";
|
import { getArgs } from "./utils.js";
|
||||||
import startFrontendDevServer from "./server-frontend-dev.js";
|
|
||||||
import startBackendServer from "./server-backend.js";
|
import startBackendServer from "./server-backend.js";
|
||||||
|
|
||||||
const SERVER_MODES = {
|
const SERVER_MODES = {
|
||||||
@ -22,10 +21,11 @@ const server_mode = args.mode === "production" ? SERVER_MODES.PRODUCTION : SERVE
|
|||||||
|
|
||||||
if (server_mode === SERVER_MODES.DEVELOPMENT) {
|
if (server_mode === SERVER_MODES.DEVELOPMENT) {
|
||||||
console.info("Starting server in development mode.");
|
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
|
// this time, it's the frontend server that is on port 8080
|
||||||
// requests for the backend will be proxied to prevent cross origins errors
|
// requests for the backend will be proxied to prevent cross origins errors
|
||||||
startBackendServer(3000);
|
startBackendServer(3000);
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
console.info("Starting server in production mode.");
|
console.info("Starting server in production mode.");
|
||||||
startBackendServer(process.env.PORT || 8080);
|
startBackendServer(process.env.PORT || 8080);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user