From 71804df3e00bf69613668888371289933969cc39 Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Thu, 11 Mar 2021 13:32:52 +0100 Subject: [PATCH] Add --dev-plugin to compile plugins on the fly Add hidden development option to run the webpack compiller for the given plugin(s) similar to the --dev option for the built-in web interface. This requires publicPath to be set in the webpack config and an updated version of webpack-dev-middleware to function correctly. --- packages/master/master.js | 21 ++++++++++++++++--- packages/master/package.json | 2 +- packages/master/webpack.config.js | 1 + plugins/global_chat/webpack.config.js | 1 + plugins/research_sync/webpack.config.js | 1 + plugins/statistics_exporter/webpack.config.js | 1 + plugins/subspace_storage/webpack.config.js | 1 + 7 files changed, 24 insertions(+), 4 deletions(-) diff --git a/packages/master/master.js b/packages/master/master.js index 7c1ce2a6..a5044424 100755 --- a/packages/master/master.js +++ b/packages/master/master.js @@ -1862,6 +1862,7 @@ async function initialize() { }) .command("run", "Run master server", yargs => { yargs.option("dev", { hidden: true, type: "boolean", nargs: 0 }); + yargs.option("dev-plugin", { hidden: true, type: "array" }); }) .demandCommand(1, "You need to specify a command to run") .strict() @@ -1954,15 +1955,29 @@ async function initialize() { async function startServer(args) { // Start webpack development server if enabled - if (args.dev) { + if (args.dev || args.devPlugin) { logger.warn("Webpack development mode enabled"); /* eslint-disable global-require */ const webpack = require("webpack"); const webpackDevMiddleware = require("webpack-dev-middleware"); - const webpackConfig = require("./webpack.config"); + const webpackConfigs = []; + if (args.dev) { + webpackConfigs.push(require("./webpack.config")); + } + if (args.devPlugin) { + for (let name of args.devPlugin) { + let info = pluginInfos.find(i => i.name === name); + if (!info) { + throw new libErrors.StartupError(`No plugin named ${name}`); + } + webpackConfigs.push( + require(path.posix.join(info.requirePath, "webpack.config")) + ); + } + } /* eslint-enable global-require */ - const compiler = webpack(webpackConfig({})); + const compiler = webpack(webpackConfigs.map(config => config({}))); devMiddleware = webpackDevMiddleware(compiler, {}); app.use(devMiddleware); } diff --git a/packages/master/package.json b/packages/master/package.json index 937d5f0a..0b22b6bb 100644 --- a/packages/master/package.json +++ b/packages/master/package.json @@ -41,7 +41,7 @@ "react-dom": "^16.13.1", "react-router-dom": "^5.2.0", "webpack-cli": "^3.3.12", - "webpack-dev-middleware": "^3.7.2", + "webpack-dev-middleware": "^4.1.0", "webpack-merge": "^5.2.0" }, "publishConfig": { diff --git a/packages/master/webpack.config.js b/packages/master/webpack.config.js index 14350778..06fd9363 100644 --- a/packages/master/webpack.config.js +++ b/packages/master/webpack.config.js @@ -12,6 +12,7 @@ module.exports = (env = {}) => merge(common(env), { contentBase: "./dist/web", }, output: { + publicPath: "/", filename: "bundle.js", path: path.resolve(__dirname, "dist", "web"), }, diff --git a/plugins/global_chat/webpack.config.js b/plugins/global_chat/webpack.config.js index 6efae364..87890343 100644 --- a/plugins/global_chat/webpack.config.js +++ b/plugins/global_chat/webpack.config.js @@ -9,6 +9,7 @@ module.exports = (env = {}) => merge(common(env), { context: __dirname, entry: "./web/index.jsx", output: { + publicPath: "/plugin/global_chat/", filename: "bundle.js", path: path.resolve(__dirname, "dist", "web"), }, diff --git a/plugins/research_sync/webpack.config.js b/plugins/research_sync/webpack.config.js index 78645a96..69ef00de 100644 --- a/plugins/research_sync/webpack.config.js +++ b/plugins/research_sync/webpack.config.js @@ -9,6 +9,7 @@ module.exports = (env = {}) => merge(common(env), { context: __dirname, entry: "./web/index.jsx", output: { + publicPath: "/plugin/research_sync/", filename: "bundle.js", path: path.resolve(__dirname, "dist", "web"), }, diff --git a/plugins/statistics_exporter/webpack.config.js b/plugins/statistics_exporter/webpack.config.js index 6ca9a1a4..3f1ee548 100644 --- a/plugins/statistics_exporter/webpack.config.js +++ b/plugins/statistics_exporter/webpack.config.js @@ -9,6 +9,7 @@ module.exports = (env = {}) => merge(common(env), { context: __dirname, entry: "./web/index.jsx", output: { + publicPath: "/plugin/statistics_exporter/", filename: "bundle.js", path: path.resolve(__dirname, "dist", "web"), }, diff --git a/plugins/subspace_storage/webpack.config.js b/plugins/subspace_storage/webpack.config.js index 65853b7f..cefb283b 100644 --- a/plugins/subspace_storage/webpack.config.js +++ b/plugins/subspace_storage/webpack.config.js @@ -9,6 +9,7 @@ module.exports = (env = {}) => merge(common(env), { context: __dirname, entry: "./web/index.jsx", output: { + publicPath: "/plugin/subspace_storage/", filename: "bundle.js", path: path.resolve(__dirname, "dist", "web"), },