mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-24 00:23:12 +09:00
Move dev server logic out of _startInternal
Break out the logic for setting up the webpack dev server into its own method to reduce the complexity of _startInternal.
This commit is contained in:
1 parent
7517917832
commit
0de70df472
1 file changed
+32
-28
@@ -165,34 +165,7 @@ export default class Controller {
|
|||||||
|
|
||||||
// Start webpack development server if enabled
|
// Start webpack development server if enabled
|
||||||
if (args.dev || args.devPlugin) {
|
if (args.dev || args.devPlugin) {
|
||||||
logger.warn("Webpack development mode enabled");
|
this._startDevServer(args);
|
||||||
/* eslint-disable @typescript-eslint/no-var-requires, node/no-unpublished-require */
|
|
||||||
const webpack = require("webpack");
|
|
||||||
const webpackDevMiddleware = require("webpack-dev-middleware");
|
|
||||||
const webpackConfigs = [];
|
|
||||||
|
|
||||||
if (args.dev) {
|
|
||||||
// eslint-disable-next-line node/no-missing-require
|
|
||||||
webpackConfigs.push(require("../../../webpack.config")({})); // Path outside of build
|
|
||||||
}
|
|
||||||
if (args.devPlugin) {
|
|
||||||
let devPlugins = new Map();
|
|
||||||
for (let name of args.devPlugin) {
|
|
||||||
let info = this.pluginInfos.find(i => i.name === name);
|
|
||||||
if (!info) {
|
|
||||||
throw new lib.StartupError(`No plugin named ${name}`);
|
|
||||||
}
|
|
||||||
let config = require(path.posix.join(info.requirePath, "webpack.config"))({});
|
|
||||||
devPlugins.set(name, webpackConfigs.length);
|
|
||||||
webpackConfigs.push(config);
|
|
||||||
}
|
|
||||||
this.app.locals.devPlugins = devPlugins;
|
|
||||||
}
|
|
||||||
/* eslint-enable @typescript-eslint/no-var-requires, node/no-unpublished-require */
|
|
||||||
|
|
||||||
const compiler = webpack(webpackConfigs);
|
|
||||||
this.devMiddleware = webpackDevMiddleware(compiler, { serverSideRender: true });
|
|
||||||
this.app.use(this.devMiddleware);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let databaseDirectory = this.config.get("controller.database_directory");
|
let databaseDirectory = this.config.get("controller.database_directory");
|
||||||
@@ -283,6 +256,37 @@ export default class Controller {
|
|||||||
this._state = "running";
|
this._state = "running";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async _startDevServer(args: ControllerArgs) {
|
||||||
|
logger.warn("Webpack development mode enabled");
|
||||||
|
/* eslint-disable @typescript-eslint/no-var-requires, node/no-unpublished-require */
|
||||||
|
const webpack = require("webpack");
|
||||||
|
const webpackDevMiddleware = require("webpack-dev-middleware");
|
||||||
|
const webpackConfigs = [];
|
||||||
|
|
||||||
|
if (args.dev) {
|
||||||
|
// eslint-disable-next-line node/no-missing-require
|
||||||
|
webpackConfigs.push(require("../../../webpack.config")({})); // Path outside of build
|
||||||
|
}
|
||||||
|
if (args.devPlugin) {
|
||||||
|
let devPlugins = new Map();
|
||||||
|
for (let name of args.devPlugin) {
|
||||||
|
let info = this.pluginInfos.find(i => i.name === name);
|
||||||
|
if (!info) {
|
||||||
|
throw new lib.StartupError(`No plugin named ${name}`);
|
||||||
|
}
|
||||||
|
let config = require(path.posix.join(info.requirePath, "webpack.config"))({});
|
||||||
|
devPlugins.set(name, webpackConfigs.length);
|
||||||
|
webpackConfigs.push(config);
|
||||||
|
}
|
||||||
|
this.app.locals.devPlugins = devPlugins;
|
||||||
|
}
|
||||||
|
/* eslint-enable @typescript-eslint/no-var-requires, node/no-unpublished-require */
|
||||||
|
|
||||||
|
const compiler = webpack(webpackConfigs);
|
||||||
|
this.devMiddleware = webpackDevMiddleware(compiler, { serverSideRender: true });
|
||||||
|
this.app.use(this.devMiddleware);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stops the controller.
|
* Stops the controller.
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in new issue
Block a user