From 579f6421e43ae4c4d44e4312e928bf9db723af08 Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Sat, 13 Mar 2021 20:21:49 +0100 Subject: [PATCH] Export web_ui as a single module Due to the way the imports and exports works with module fedderation each require path needs it's own shared module in the plugin. To avoid having to specify every possible import in the module federation plugin config, export all useful components to plugins in the browser entrypoint for web_ui. Note that for some reason the module wouldn't exist for import by plugins unless some part of the build imported it. Which is the reason for the master index.jsx to import bootstrap via it. --- packages/master/web/index.jsx | 4 +++- packages/master/webpack.config.js | 1 - packages/web_ui/package.json | 1 + packages/web_ui/src/bootstrap.jsx | 4 +--- packages/web_ui/src/index.jsx | 20 ++++++++++++++++++++ 5 files changed, 25 insertions(+), 5 deletions(-) create mode 100644 packages/web_ui/src/index.jsx diff --git a/packages/master/web/index.jsx b/packages/master/web/index.jsx index 30fdbf62..64be3a06 100644 --- a/packages/master/web/index.jsx +++ b/packages/master/web/index.jsx @@ -1 +1,3 @@ -import("@clusterio/web_ui/src/bootstrap"); +import("@clusterio/web_ui").then(webUi => { + return webUi.bootstrap(); +}).catch(console.error); diff --git a/packages/master/webpack.config.js b/packages/master/webpack.config.js index 06fd9363..16223c8b 100644 --- a/packages/master/webpack.config.js +++ b/packages/master/webpack.config.js @@ -29,7 +29,6 @@ module.exports = (env = {}) => merge(common(env), { "@clusterio/lib/schema": { singleton: true }, "@clusterio/lib/users": { singleton: true }, "@clusterio/web_ui": { singleton: true }, - "ajv": {}, "antd": { singleton: true }, "react": { singleton: true }, "react-dom": { singleton: true }, diff --git a/packages/web_ui/package.json b/packages/web_ui/package.json index 5a4fe02a..3adf1e6c 100644 --- a/packages/web_ui/package.json +++ b/packages/web_ui/package.json @@ -4,6 +4,7 @@ "author": "Hornwitser", "license": "MIT", "version": "2.0.0-alpha.4", + "browser": "src/index.jsx", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, diff --git a/packages/web_ui/src/bootstrap.jsx b/packages/web_ui/src/bootstrap.jsx index ee217769..0e37a489 100644 --- a/packages/web_ui/src/bootstrap.jsx +++ b/packages/web_ui/src/bootstrap.jsx @@ -74,7 +74,7 @@ async function loadPlugins() { return plugins; } -async function load() { +export default async function bootstrap() { logger.add(new ConsoleTransport({ level: "verbose", format: new WebConsoleFormat(), @@ -92,5 +92,3 @@ async function load() { ReactDOM.render(, document.getElementById("root")); } - -load().catch((err) => logger.fatal(err.stack)); diff --git a/packages/web_ui/src/index.jsx b/packages/web_ui/src/index.jsx new file mode 100644 index 00000000..dc3e9887 --- /dev/null +++ b/packages/web_ui/src/index.jsx @@ -0,0 +1,20 @@ +export { default as basename } from "./basename.jsx"; +export { default as bootstrap } from "./bootstrap.jsx"; +export { default as notify, notifyErrorHandler } from "./util/notify.jsx"; + +export * from "./model/instance.jsx"; +export * from "./model/slave.jsx"; + + +export { default as ControlContext } from "./components/ControlContext"; +export { default as PluginsContext } from "./components/PluginsContext"; + +export { default as BaseConfigTree } from "./components/BaseConfigTree"; +export { default as InstanceConfigTree } from "./components/InstanceConfigTree"; +export { default as MasterConfigTree } from "./components/MasterConfigTree"; + +export { default as AssignInstanceModal } from "./components/AssignInstanceModal"; +export { default as InstanceConsole } from "./components/InstanceConsole"; +export { default as InstanceRcon } from "./components/InstanceRcon"; + +export { default as PageLayout } from "./components/PageLayout";