build: enable frontend module code splitting
This commit is contained in:
@@ -67,7 +67,10 @@ await build({
|
||||
},
|
||||
outdir: outputDir,
|
||||
bundle: true,
|
||||
format: "iife",
|
||||
format: "esm",
|
||||
splitting: true,
|
||||
entryNames: "[name]",
|
||||
chunkNames: "chunk-[hash]",
|
||||
platform: "browser",
|
||||
target: "es2022",
|
||||
sourcemap: false,
|
||||
|
||||
@@ -6,6 +6,7 @@ import assert from "node:assert/strict";
|
||||
import { readFile } from "node:fs/promises";
|
||||
import test from "node:test";
|
||||
import vm from "node:vm";
|
||||
import { bundleEntry } from "./bundle-entry.mjs";
|
||||
|
||||
test("APRS entry normalizes positioned packets without remote symbol assets", async () => {
|
||||
const forwarded = [];
|
||||
@@ -26,7 +27,7 @@ test("APRS entry normalizes positioned packets without remote symbol assets", as
|
||||
console,
|
||||
});
|
||||
const runtime = await readFile(new URL("../../assets/web/generated/plugin-runtime.js", import.meta.url), "utf8");
|
||||
const source = await readFile(new URL("../../assets/web/generated/aprs.js", import.meta.url), "utf8");
|
||||
const source = await bundleEntry(new URL("../src/plugins/aprs.ts", import.meta.url));
|
||||
assert.equal(source.includes("raw.githubusercontent.com"), false);
|
||||
new vm.Script(runtime).runInContext(context);
|
||||
new vm.Script(source).runInContext(context);
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
// SPDX-FileCopyrightText: 2026 Stan Grams <sjg@haxx.space>
|
||||
//
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
import { build } from "esbuild";
|
||||
|
||||
export async function bundleEntry(entryUrl) {
|
||||
const result = await build({
|
||||
entryPoints: [entryUrl.pathname],
|
||||
bundle: true,
|
||||
format: "iife",
|
||||
platform: "browser",
|
||||
target: "es2022",
|
||||
write: false,
|
||||
});
|
||||
const output = result.outputFiles[0];
|
||||
if (!output) throw new Error(`No bundle output for ${entryUrl.pathname}`);
|
||||
return output.text;
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import assert from "node:assert/strict";
|
||||
import { readFile } from "node:fs/promises";
|
||||
import test from "node:test";
|
||||
import vm from "node:vm";
|
||||
import { bundleEntry } from "./bundle-entry.mjs";
|
||||
|
||||
test("FT2 entry normalizes audio offsets and registers typed callbacks", async () => {
|
||||
let barRenderer;
|
||||
@@ -30,7 +31,7 @@ test("FT2 entry normalizes audio offsets and registers typed callbacks", async (
|
||||
console,
|
||||
});
|
||||
const runtime = await readFile(new URL("../../assets/web/generated/plugin-runtime.js", import.meta.url), "utf8");
|
||||
const source = await readFile(new URL("../../assets/web/generated/ft2.js", import.meta.url), "utf8");
|
||||
const source = await bundleEntry(new URL("../src/plugins/ft2.ts", import.meta.url));
|
||||
new vm.Script(runtime).runInContext(context);
|
||||
new vm.Script(source).runInContext(context);
|
||||
|
||||
@@ -62,7 +63,7 @@ test("FT8 entry installs shared parsing without relying on script globals", asyn
|
||||
console,
|
||||
});
|
||||
const runtime = await readFile(new URL("../../assets/web/generated/plugin-runtime.js", import.meta.url), "utf8");
|
||||
const source = await readFile(new URL("../../assets/web/generated/ft8.js", import.meta.url), "utf8");
|
||||
const source = await bundleEntry(new URL("../src/plugins/ft8.ts", import.meta.url));
|
||||
new vm.Script(runtime).runInContext(context);
|
||||
new vm.Script(source).runInContext(context);
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import assert from "node:assert/strict";
|
||||
import { readFile } from "node:fs/promises";
|
||||
import test from "node:test";
|
||||
import vm from "node:vm";
|
||||
import { bundleEntry } from "./bundle-entry.mjs";
|
||||
|
||||
test("HF APRS entry uses shared typed normalization and local symbols", async () => {
|
||||
const window = { trxUi: { confirm: async () => true } };
|
||||
@@ -22,7 +23,7 @@ test("HF APRS entry uses shared typed normalization and local symbols", async ()
|
||||
console,
|
||||
});
|
||||
const runtime = await readFile(new URL("../../assets/web/generated/plugin-runtime.js", import.meta.url), "utf8");
|
||||
const source = await readFile(new URL("../../assets/web/generated/hf-aprs.js", import.meta.url), "utf8");
|
||||
const source = await bundleEntry(new URL("../src/plugins/hf-aprs.ts", import.meta.url));
|
||||
assert.equal(source.includes("raw.githubusercontent.com"), false);
|
||||
new vm.Script(runtime).runInContext(context);
|
||||
new vm.Script(source).runInContext(context);
|
||||
|
||||
Reference in New Issue
Block a user