mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-18 07:33:12 +09:00
Build the web interface and plugins with Vite
Replace webpack and Module Federation with Vite 8. The controller build emits one entry per shared module (lib, web_ui, typebox, antd, react, react-dom, react-router) and lists them in manifest.json. The controller turns that into an import map in index.html, and plugins are built as ES modules that import the shared modules by name and are loaded with import(). The shared Vite setup lives in @clusterio/web_ui/vite.mjs. Plugins use clusterioPlugin(), which exposes index, package.json and web/index under the same keys the webpack template used. The --dev and --dev-plugin flags now run the Vite dev server in middleware mode with hot module replacement. Browser polyfills move from web_ui to lib, which is the code that needs them, and lib sets the process and Buffer globals itself. Refs #1127 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
35125a28ab
commit
3227179613
57 files changed
+616
-620
No files matched your search
@@ -181,7 +181,10 @@ describe("controller/src/Controller", function() {
|
||||
before(async function() {
|
||||
const app = express();
|
||||
app.locals.controller = { config: { get: () => "Test Cluster" } };
|
||||
app.locals.mainBundle = "static/main.abc.js";
|
||||
app.locals.webBundle = {
|
||||
main: "static/main.abc.js",
|
||||
imports: { "react": "static/shared-react.abc.js" },
|
||||
};
|
||||
for (let route of ["/", "/instances/:id/view"]) {
|
||||
app.get(route, Controller.serveWeb(route));
|
||||
}
|
||||
@@ -199,12 +202,14 @@ describe("controller/src/Controller", function() {
|
||||
assert(html.includes("src=\"./static/main.abc.js\""));
|
||||
assert(html.includes("new URL(\"./\", document.location)"));
|
||||
assert(html.includes("new URL(\"./static/\", document.location)"));
|
||||
assert(html.includes('{"imports":{"react":"./static/shared-react.abc.js"}}'));
|
||||
});
|
||||
it("should use relative roots for nested routes", async function() {
|
||||
let html = await (await fetch(`http://localhost:${port}/instances/1/view`)).text();
|
||||
assert(html.includes("src=\"../../static/main.abc.js\""));
|
||||
assert(html.includes("new URL(\"../../\", document.location)"));
|
||||
assert(html.includes("new URL(\"../../static/\", document.location)"));
|
||||
assert(html.includes('{"imports":{"react":"../../static/shared-react.abc.js"}}'));
|
||||
html = await (await fetch(`http://localhost:${port}/instances/1/view/`)).text();
|
||||
assert(html.includes("src=\"../../../static/main.abc.js\""));
|
||||
assert(html.includes("new URL(\"../../../static/\", document.location)"));
|
||||
|
||||
@@ -157,7 +157,7 @@ describe("controller/src/routes", function() {
|
||||
it("should strip static/ from the plugin bundle path", async function() {
|
||||
controller.pluginInfos = [{
|
||||
name: "foo", version: "1.0.0", npmPackage: "foo",
|
||||
manifest: { "foo.js": "static/foo.abc.js" },
|
||||
manifest: { main: "static/foo.abc.js" },
|
||||
}];
|
||||
controller.loadedPlugins = new Set(controller.pluginInfos);
|
||||
let response = await fetch(endpoint);
|
||||
@@ -171,15 +171,16 @@ describe("controller/src/routes", function() {
|
||||
controller.pluginInfos = [
|
||||
{ name: "foo", version: "1.0.0", npmPackage: "foo", webEntrypoint: "dist/web/index.js" },
|
||||
{ name: "bar", version: "1.0.0", npmPackage: "bar", manifest: {} },
|
||||
{ name: "baz", version: "1.0.0", npmPackage: "baz", manifest: { "baz.js": "remoteEntry.js" } },
|
||||
{ name: "baz", version: "1.0.0", npmPackage: "baz", manifest: { "baz.js": "static/baz.abc.js" } },
|
||||
];
|
||||
controller.loadedPlugins = new Set([controller.pluginInfos[0]]);
|
||||
let response = await fetch(endpoint);
|
||||
assert.equal(response.status, 200);
|
||||
let data = await response.json();
|
||||
assert.equal(data[0].web.error, "Missing dist/web/manifest.json");
|
||||
assert.equal(data[1].web.error, "Missing bar.js entry in manifest.json");
|
||||
assert.equal(data[2].web.error, "Incompatible old remoteEntry.js entrypoint.");
|
||||
const incompatible = "Incompatible dist/web/manifest.json, the plugin must be rebuilt with Vite";
|
||||
assert.equal(data[1].web.error, incompatible);
|
||||
assert.equal(data[2].web.error, incompatible);
|
||||
assert.equal(data[1].loaded, false);
|
||||
assert.equal(data[1].enabled, false);
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user