mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-04 10:24:02 +00:00
Run the worker prelude ahead of Cesium's own workers script
Cesium's script sets CESIUM_WORKERS itself when it loads, so the panel's combined workers script was never used, and neither was the embedded terrain-heights file: the worker still requested it from the panel page's site. The panel build now writes only the prelude, and the panel puts it ahead of whatever Cesium assigns to CESIUM_WORKERS. The separate esbuild bundle of Cesium's workers is gone.
This commit is contained in:
1 parent
9e5ef78f91
commit
e82ab7440d
6 files changed
+38
-65
No files matched your search
+6
-22
@@ -4,25 +4,22 @@
|
||||
* See build/panel.js.
|
||||
*/
|
||||
|
||||
import { readFile, readdir, rename, rm, writeFile } from 'node:fs/promises';
|
||||
import { readFile, rename, rm, writeFile } from 'node:fs/promises';
|
||||
import { join } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { build as esbuild } from 'esbuild';
|
||||
import { build } from 'vite';
|
||||
import standaloneConfig from '../server/standalone/vite.config.js';
|
||||
import {
|
||||
PANEL_BASE,
|
||||
PANEL_OUT_DIR,
|
||||
PANEL_WORKER_FILES,
|
||||
PANEL_WORKERS_PATH,
|
||||
PANEL_WORKER_PRELUDE_PATH,
|
||||
panelBuildConfig,
|
||||
workerFilesPrelude,
|
||||
workersEntrySource,
|
||||
} from '../build/panel.js';
|
||||
|
||||
const root = fileURLToPath(new URL('../', import.meta.url));
|
||||
const outDir = join(root, PANEL_OUT_DIR);
|
||||
const cesiumWorkers = join(root, 'node_modules/cesium/Build/Cesium/Workers');
|
||||
|
||||
const config = standaloneConfig({ command: 'build', mode: 'production' });
|
||||
await build({
|
||||
@@ -37,26 +34,13 @@ await rm(join(outDir, 'cesium'), { recursive: true, force: true });
|
||||
await rename(nested, join(outDir, 'cesium'));
|
||||
await rm(join(outDir, PANEL_BASE.split('/')[1]), { recursive: true });
|
||||
|
||||
const names = (await readdir(cesiumWorkers))
|
||||
.filter((file) => file.endsWith('.js') && !file.startsWith('chunk-'))
|
||||
.map((file) => file.slice(0, -3));
|
||||
const entry = join(outDir, 'cesium', 'workers-entry.js');
|
||||
await writeFile(entry, workersEntrySource(names, cesiumWorkers));
|
||||
await esbuild({
|
||||
entryPoints: [entry],
|
||||
bundle: true,
|
||||
format: 'iife',
|
||||
minify: true,
|
||||
outfile: join(outDir, PANEL_WORKERS_PATH),
|
||||
logLevel: 'warning',
|
||||
});
|
||||
await rm(entry);
|
||||
// Cesium's workers load these files themselves; embed them in a prelude the
|
||||
// panel runs ahead of Cesium's workers script.
|
||||
const files = {};
|
||||
for (const name of PANEL_WORKER_FILES)
|
||||
files[name] = await readFile(join(outDir, 'cesium', name), 'utf8');
|
||||
const workers = join(outDir, PANEL_WORKERS_PATH);
|
||||
await writeFile(
|
||||
workers,
|
||||
workerFilesPrelude(files) + (await readFile(workers, 'utf8')),
|
||||
join(outDir, PANEL_WORKER_PRELUDE_PATH),
|
||||
workerFilesPrelude(files),
|
||||
);
|
||||
console.log(`Panel build written to ${PANEL_OUT_DIR}`);
|
||||
Reference in new issue
Block a user