@xgis/xgis3d-build 0.3.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Republic of Estonia Land and Spatial Development Board
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,141 @@
1
+ # @xgis/xgis3d-build
2
+
3
+ Build-tool integration for [`@xgis/xgis3d`](../xgis3d/README.md). Copies CesiumJS's runtime assets
4
+ into your build output, serves them in dev, and sets `window.CESIUM_BASE_URL` so Cesium finds them.
5
+
6
+ Part of the [XGIS3D monorepo](../../README.md).
7
+
8
+ ## Install
9
+
10
+ Needed for `mapMode: '3d'` or `'both'`. A 2D-only application does not need it.
11
+
12
+ ```bash
13
+ pnpm add -D @xgis/xgis3d-build
14
+ ```
15
+
16
+ `@xgis/xgis3d` is a required peer. `vite` and `@rspack/core` are optional — install whichever you
17
+ build with. Do not install `cesium`; this package reads the copy `@xgis/xgis3d` pins.
18
+
19
+ ## Vite
20
+
21
+ ```typescript
22
+ // vite.config.ts
23
+ import { cesiumAssets } from '@xgis/xgis3d-build/vite'
24
+
25
+ export default defineConfig({
26
+ plugins: [react(), cesiumAssets()],
27
+ })
28
+ ```
29
+
30
+ Handles dev and build. Respects `base`, including a full CDN origin. Working example:
31
+ [`examples/npm-vite/`](../../examples/npm-vite).
32
+
33
+ ## Rspack
34
+
35
+ ```javascript
36
+ // rspack.config.mjs
37
+ import { CesiumAssetsRspackPlugin } from '@xgis/xgis3d-build/rspack'
38
+
39
+ export default {
40
+ plugins: [
41
+ new rspack.HtmlRspackPlugin({ template: './index.html' }),
42
+ new CesiumAssetsRspackPlugin(),
43
+ ],
44
+ }
45
+ ```
46
+
47
+ Requires `HtmlRspackPlugin` — that is where the base URL is injected, and the plugin warns at build
48
+ time if it is absent. It also adds the assets to `devServer.static`. Working example:
49
+ [`examples/npm-rspack/`](../../examples/npm-rspack).
50
+
51
+ ## Other build tools
52
+
53
+ For webpack, an ejected CRA, esbuild, or no bundler: copy the assets into a directory your build
54
+ already serves, and paste the printed tag into your HTML.
55
+
56
+ ```bash
57
+ npx xgis-cesium-assets copy public
58
+ ```
59
+
60
+ ```
61
+ Copied 4 Cesium asset directories and LICENSE.md to /app/public/cesium-1.143.0
62
+
63
+ Add this to the <head> of your HTML, before any bundle script:
64
+ <script>window.CESIUM_BASE_URL="/cesium-1.143.0"</script>
65
+ ```
66
+
67
+ | Flag | Effect |
68
+ | ------------------- | ------------------------------------------------------------------- |
69
+ | `--base <name>` | Directory name under the target. Default `cesium-<version>` |
70
+ | `--public-path <p>` | URL prefix for the printed tag, when the target is not the web root |
71
+
72
+ Call it from a script rather than a `prebuild`/`prestart` hook — pnpm does not run npm pre/post
73
+ lifecycle scripts by default:
74
+
75
+ ```json
76
+ {
77
+ "scripts": {
78
+ "copy-cesium": "xgis-cesium-assets copy public",
79
+ "build": "pnpm copy-cesium && react-scripts build"
80
+ }
81
+ }
82
+ ```
83
+
84
+ ## API
85
+
86
+ The package root exports the bundler-independent core, for a build tool none of the above covers.
87
+
88
+ ```typescript
89
+ import { copyCesiumAssets, planCesiumAssets } from '@xgis/xgis3d-build'
90
+
91
+ const plan = planCesiumAssets({ base: 'cesium' })
92
+ // { source, licenseFile, dir, entries }
93
+
94
+ copyCesiumAssets(plan, 'dist')
95
+ ```
96
+
97
+ | Export | Purpose |
98
+ | --------------------------------- | ----------------------------------------------------------- |
99
+ | `planCesiumAssets(options?)` | Resolves Cesium, returns paths and the directory name |
100
+ | `copyCesiumAssets(plan, outDir)` | Copies the four asset directories plus `LICENSE.md` |
101
+ | `joinPublicPath(prefix, dir)` | Joins a build-tool path prefix with the asset directory |
102
+ | `cesiumBaseUrlScript(publicPath)` | The `window.CESIUM_BASE_URL=…` assignment, escaped for HTML |
103
+
104
+ `planCesiumAssets` throws on a `base` that is empty, traverses upwards, or contains `\` — it becomes
105
+ both a URL segment and a directory name.
106
+
107
+ ## What lives here
108
+
109
+ | File | Responsibility |
110
+ | ------------------ | ---------------------------------------------------------- |
111
+ | `cesiumAssets.ts` | The core. Resolve, plan, copy, base-URL string. No bundler |
112
+ | `vite-plugin.ts` | `cesiumAssets()` |
113
+ | `rspack-plugin.ts` | `CesiumAssetsRspackPlugin` |
114
+ | `cliRun.ts` | `runCli()`, behind the `xgis-cesium-assets` bin |
115
+
116
+ All of it runs in Node under a consumer's build config. `tsconfig.json` sets `lib: ["ES2023"]` with
117
+ no DOM, so a browser API reaching this package fails to compile.
118
+
119
+ ## Dependency policy
120
+
121
+ `sirv` is a runtime dependency rather than a dev one: the consumer's Vite dev server loads it, and a
122
+ devDependency is not installed for consumers.
123
+
124
+ `cesium` is neither a dependency nor a peer. It is resolved through `@xgis/xgis3d`, so the assets
125
+ copied are always the ones that runtime was built against:
126
+
127
+ ```typescript
128
+ const requireFromXgis3d = createRequire(requireFromHere.resolve('@xgis/xgis3d/package.json'))
129
+
130
+ requireFromXgis3d.resolve('cesium/package.json')
131
+ ```
132
+
133
+ ## Docs
134
+
135
+ - [Integration guide](../../docs/integration-guide.md) — Section 1, Cesium assets
136
+ - [ADR-0022](../../docs/decisions/0022-bundler-agnostic-cesium-assets.md) — why this is a separate
137
+ package, and why the base URL is not set with `define`
138
+
139
+ ## License
140
+
141
+ MIT. See [LICENSE](./LICENSE).
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env node
2
+ import { runCli } from '../dist/cliRun.js'
3
+
4
+ try {
5
+ process.stdout.write(`${runCli(process.argv.slice(2))}\n`)
6
+ } catch (error) {
7
+ process.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`)
8
+ // Not process.exit: when stderr is a pipe the write is async and exit truncates it, leaving CI
9
+ // logs with an exit code and no message.
10
+ process.exitCode = 1
11
+ }
@@ -0,0 +1,22 @@
1
+ export declare const CESIUM_ASSET_ENTRIES: readonly ["Workers", "ThirdParty", "Assets", "Widgets"];
2
+ export interface CesiumAssetsOptions {
3
+ /**
4
+ * Directory the assets are served under. Must match `window.CESIUM_BASE_URL`.
5
+ * Defaults to `cesium-<version>`, which is what `ensureCesiumBaseUrl()` sets.
6
+ */
7
+ base?: string;
8
+ }
9
+ export interface CesiumAssetPlan {
10
+ readonly source: string;
11
+ readonly licenseFile: string;
12
+ readonly dir: string;
13
+ readonly entries: readonly string[];
14
+ }
15
+ export declare function planCesiumAssets(options?: CesiumAssetsOptions): CesiumAssetPlan;
16
+ export declare function copyCesiumAssets(plan: CesiumAssetPlan, outDir: string): void;
17
+ /**
18
+ * Joins a build-tool path prefix (Vite `base`, Rspack `output.publicPath`) with the asset
19
+ * directory. An empty prefix means "relative to the document", which is a deliberate setting.
20
+ */
21
+ export declare function joinPublicPath(prefix: string, dir: string): string;
22
+ export declare function cesiumBaseUrlScript(publicPath: string): string;
@@ -0,0 +1,58 @@
1
+ import { readFileSync, existsSync, cpSync, realpathSync } from 'node:fs';
2
+ import { createRequire } from 'node:module';
3
+ import { join, dirname } from 'node:path';
4
+
5
+ const CESIUM_ASSET_ENTRIES = ["Workers", "ThirdParty", "Assets", "Widgets"];
6
+ const requireFromHere = createRequire(import.meta.url);
7
+ function cesiumPackageDir() {
8
+ const xgis3dManifest = requireFromHere.resolve("@xgis/xgis3d/package.json");
9
+ const requireFromXgis3d = createRequire(xgis3dManifest);
10
+ return dirname(realpathSync(requireFromXgis3d.resolve("cesium/package.json")));
11
+ }
12
+ function normaliseDir(base) {
13
+ const dir = base.replace(/^\/+/, "").replace(/\/+$/, "").replace(/\/{2,}/g, "/");
14
+ if (!dir) {
15
+ throw new Error(`cesiumAssets: base must name a directory, got ${JSON.stringify(base)}`);
16
+ }
17
+ if (dir.includes("\\")) {
18
+ throw new Error(`cesiumAssets: base must use "/" as a separator, got ${JSON.stringify(base)}`);
19
+ }
20
+ if (dir.split("/").includes("..")) {
21
+ throw new Error(`cesiumAssets: base must not traverse upwards, got ${JSON.stringify(base)}`);
22
+ }
23
+ return dir;
24
+ }
25
+ function planCesiumAssets(options = {}) {
26
+ const packageDir = cesiumPackageDir();
27
+ const manifest = JSON.parse(readFileSync(join(packageDir, "package.json"), "utf8"));
28
+ const source = join(packageDir, "Build", "Cesium");
29
+ if (!existsSync(source)) {
30
+ throw new Error(`cesiumAssets: Cesium build output not found at ${source}`);
31
+ }
32
+ return {
33
+ source,
34
+ licenseFile: join(packageDir, "LICENSE.md"),
35
+ dir: normaliseDir(options.base ?? `cesium-${manifest.version}`),
36
+ entries: CESIUM_ASSET_ENTRIES
37
+ };
38
+ }
39
+ function copyCesiumAssets(plan, outDir) {
40
+ for (const entry of plan.entries) {
41
+ cpSync(join(plan.source, entry), join(outDir, plan.dir, entry), { recursive: true });
42
+ }
43
+ cpSync(plan.licenseFile, join(outDir, plan.dir, "LICENSE.md"));
44
+ }
45
+ function joinPublicPath(prefix, dir) {
46
+ if (!prefix) {
47
+ return dir;
48
+ }
49
+ const origin = /^[a-z][a-z0-9+.-]*:\/\/[^/]*/i.exec(prefix)?.[0] ?? "";
50
+ const path = `${prefix.slice(origin.length)}/${dir}`.replace(/\/{2,}/g, "/");
51
+ return `${origin}${path}`;
52
+ }
53
+ function cesiumBaseUrlScript(publicPath) {
54
+ return `window.CESIUM_BASE_URL=${JSON.stringify(publicPath).replace(/</g, "\\u003c")}`;
55
+ }
56
+
57
+ export { CESIUM_ASSET_ENTRIES, cesiumBaseUrlScript, copyCesiumAssets, joinPublicPath, planCesiumAssets };
58
+ //# sourceMappingURL=cesiumAssets.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cesiumAssets.js","sources":["../src/cesiumAssets.ts"],"sourcesContent":["import { cpSync, existsSync, readFileSync, realpathSync } from 'node:fs'\nimport { createRequire } from 'node:module'\nimport { dirname, join } from 'node:path'\n\n// Cesium loads these dynamically at runtime; a bundler bundles the JS library but never sees them.\nexport const CESIUM_ASSET_ENTRIES = ['Workers', 'ThirdParty', 'Assets', 'Widgets'] as const\n\nexport interface CesiumAssetsOptions {\n /**\n * Directory the assets are served under. Must match `window.CESIUM_BASE_URL`.\n * Defaults to `cesium-<version>`, which is what `ensureCesiumBaseUrl()` sets.\n */\n base?: string\n}\n\nexport interface CesiumAssetPlan {\n readonly source: string\n readonly licenseFile: string\n readonly dir: string\n readonly entries: readonly string[]\n}\n\n// Read rather than imported: the library build strips the attribute a bare .json import needs.\nconst requireFromHere = createRequire(import.meta.url)\n\n// Through @xgis/xgis3d, so the copied assets are the ones its runtime was built against.\nfunction cesiumPackageDir(): string {\n const xgis3dManifest = requireFromHere.resolve('@xgis/xgis3d/package.json')\n const requireFromXgis3d = createRequire(xgis3dManifest)\n\n return dirname(realpathSync(requireFromXgis3d.resolve('cesium/package.json')))\n}\n\n// `dir` is used as both a URL segment and a filesystem segment, so it has to be safe as both.\nfunction normaliseDir(base: string): string {\n const dir = base\n .replace(/^\\/+/, '')\n .replace(/\\/+$/, '')\n .replace(/\\/{2,}/g, '/')\n\n if (!dir) {\n throw new Error(`cesiumAssets: base must name a directory, got ${JSON.stringify(base)}`)\n }\n\n if (dir.includes('\\\\')) {\n throw new Error(`cesiumAssets: base must use \"/\" as a separator, got ${JSON.stringify(base)}`)\n }\n\n // Without this, `--base ../..` writes Cesium's build tree outside the output directory.\n if (dir.split('/').includes('..')) {\n throw new Error(`cesiumAssets: base must not traverse upwards, got ${JSON.stringify(base)}`)\n }\n\n return dir\n}\n\nexport function planCesiumAssets(options: CesiumAssetsOptions = {}): CesiumAssetPlan {\n const packageDir = cesiumPackageDir()\n const manifest = JSON.parse(readFileSync(join(packageDir, 'package.json'), 'utf8')) as {\n version: string\n }\n const source = join(packageDir, 'Build', 'Cesium')\n\n // Named here rather than as a bare ENOENT at the end of a long build.\n if (!existsSync(source)) {\n throw new Error(`cesiumAssets: Cesium build output not found at ${source}`)\n }\n\n return {\n source,\n licenseFile: join(packageDir, 'LICENSE.md'),\n dir: normaliseDir(options.base ?? `cesium-${manifest.version}`),\n entries: CESIUM_ASSET_ENTRIES,\n }\n}\n\nexport function copyCesiumAssets(plan: CesiumAssetPlan, outDir: string): void {\n for (const entry of plan.entries) {\n cpSync(join(plan.source, entry), join(outDir, plan.dir, entry), { recursive: true })\n }\n\n // Redistribution: Apache-2.0 4(a) for Cesium, BSD-3-Clause for ThirdParty/. LICENSE.md covers both.\n cpSync(plan.licenseFile, join(outDir, plan.dir, 'LICENSE.md'))\n}\n\n/**\n * Joins a build-tool path prefix (Vite `base`, Rspack `output.publicPath`) with the asset\n * directory. An empty prefix means \"relative to the document\", which is a deliberate setting.\n */\nexport function joinPublicPath(prefix: string, dir: string): string {\n if (!prefix) {\n return dir\n }\n\n // Only the path collapses; `https://cdn/` would otherwise become `https:/cdn/`.\n const origin = /^[a-z][a-z0-9+.-]*:\\/\\/[^/]*/i.exec(prefix)?.[0] ?? ''\n const path = `${prefix.slice(origin.length)}/${dir}`.replace(/\\/{2,}/g, '/')\n\n return `${origin}${path}`\n}\n\nexport function cesiumBaseUrlScript(publicPath: string): string {\n // Emitted as raw inline script content, and JSON.stringify escapes quotes but not `<`.\n return `window.CESIUM_BASE_URL=${JSON.stringify(publicPath).replace(/</g, '\\\\u003c')}`\n}\n"],"names":[],"mappings":";;;;AAKO,MAAM,oBAAA,GAAuB,CAAC,SAAA,EAAW,YAAA,EAAc,UAAU,SAAS;AAkBjF,MAAM,eAAA,GAAkB,aAAA,CAAc,MAAA,CAAA,IAAA,CAAY,GAAG,CAAA;AAGrD,SAAS,gBAAA,GAA2B;AAClC,EAAA,MAAM,cAAA,GAAiB,eAAA,CAAgB,OAAA,CAAQ,2BAA2B,CAAA;AAC1E,EAAA,MAAM,iBAAA,GAAoB,cAAc,cAAc,CAAA;AAEtD,EAAA,OAAO,QAAQ,YAAA,CAAa,iBAAA,CAAkB,OAAA,CAAQ,qBAAqB,CAAC,CAAC,CAAA;AAC/E;AAGA,SAAS,aAAa,IAAA,EAAsB;AAC1C,EAAA,MAAM,GAAA,GAAM,IAAA,CACT,OAAA,CAAQ,MAAA,EAAQ,EAAE,CAAA,CAClB,OAAA,CAAQ,MAAA,EAAQ,EAAE,CAAA,CAClB,OAAA,CAAQ,SAAA,EAAW,GAAG,CAAA;AAEzB,EAAA,IAAI,CAAC,GAAA,EAAK;AACR,IAAA,MAAM,IAAI,KAAA,CAAM,CAAA,8CAAA,EAAiD,KAAK,SAAA,CAAU,IAAI,CAAC,CAAA,CAAE,CAAA;AAAA,EACzF;AAEA,EAAA,IAAI,GAAA,CAAI,QAAA,CAAS,IAAI,CAAA,EAAG;AACtB,IAAA,MAAM,IAAI,KAAA,CAAM,CAAA,oDAAA,EAAuD,KAAK,SAAA,CAAU,IAAI,CAAC,CAAA,CAAE,CAAA;AAAA,EAC/F;AAGA,EAAA,IAAI,IAAI,KAAA,CAAM,GAAG,CAAA,CAAE,QAAA,CAAS,IAAI,CAAA,EAAG;AACjC,IAAA,MAAM,IAAI,KAAA,CAAM,CAAA,kDAAA,EAAqD,KAAK,SAAA,CAAU,IAAI,CAAC,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AAA;AAAA,EACT;AAGA,EAAA,MAAM,SAAS,+BAAA,CAAgC,IAAA,CAAK,MAAM,CAAA,GAAI,CAAC,CAAA,IAAK,EAAA;AACpE,EAAA,MAAM,IAAA,GAAO,CAAA,EAAG,MAAA,CAAO,KAAA,CAAM,MAAA,CAAO,MAAM,CAAC,CAAA,CAAA,EAAI,GAAG,CAAA,CAAA,CAAG,OAAA,CAAQ,SAAA,EAAW,GAAG,CAAA;AAE3E,EAAA,OAAO,CAAA,EAAG,MAAM,CAAA,EAAG,IAAI,CAAA,CAAA;AACzB;AAEO,SAAS,oBAAoB,UAAA,EAA4B;AAE9D,EAAA,OAAO,CAAA,uBAAA,EAA0B,KAAK,SAAA,CAAU,UAAU,EAAE,OAAA,CAAQ,IAAA,EAAM,SAAS,CAAC,CAAA,CAAA;AACtF;;;;"}
@@ -0,0 +1 @@
1
+ export declare function runCli(argv: string[]): string;
package/dist/cliRun.js ADDED
@@ -0,0 +1,54 @@
1
+ import { resolve } from 'node:path';
2
+ import { planCesiumAssets, copyCesiumAssets, joinPublicPath, cesiumBaseUrlScript } from './cesiumAssets.js';
3
+
4
+ const USAGE = "Usage: xgis-cesium-assets copy <dir> [--base <name>] [--public-path <prefix>]";
5
+ function runCli(argv) {
6
+ const [command, target, ...rest] = argv;
7
+ if (command !== "copy") {
8
+ throw new Error(`Unknown command: ${command ?? "(none)"}
9
+ ${USAGE}`);
10
+ }
11
+ if (!target || target.startsWith("-")) {
12
+ throw new Error(`Expected a target directory, got ${target ?? "(none)"}
13
+ ${USAGE}`);
14
+ }
15
+ const plan = planCesiumAssets({ base: readFlag(rest, "--base") });
16
+ const outDir = resolve(process.cwd(), target);
17
+ copyCesiumAssets(plan, outDir);
18
+ const publicPath = joinPublicPath(readFlag(rest, "--public-path") ?? "/", plan.dir);
19
+ return [
20
+ `Copied ${plan.entries.length} Cesium asset directories and LICENSE.md to ${outDir}/${plan.dir}`,
21
+ "",
22
+ "Add this to the <head> of your HTML, before any bundle script:",
23
+ ` <script>${cesiumBaseUrlScript(publicPath)}<\/script>`,
24
+ "",
25
+ `If ${target} is not served at the site root, re-run with --public-path <prefix> to get the`,
26
+ "right value, or adjust the path above to match."
27
+ ].join("\n");
28
+ }
29
+ function readFlag(args, flag) {
30
+ const inline = args.find((arg) => arg.startsWith(`${flag}=`));
31
+ if (inline) {
32
+ return requireValue(inline.slice(flag.length + 1), flag);
33
+ }
34
+ const index = args.indexOf(flag);
35
+ if (index === -1) {
36
+ return void 0;
37
+ }
38
+ const value = args[index + 1];
39
+ if (value === void 0 || value.startsWith("-")) {
40
+ throw new Error(`${flag} needs a value
41
+ ${USAGE}`);
42
+ }
43
+ return requireValue(value, flag);
44
+ }
45
+ function requireValue(value, flag) {
46
+ if (!value) {
47
+ throw new Error(`${flag} needs a value
48
+ ${USAGE}`);
49
+ }
50
+ return value;
51
+ }
52
+
53
+ export { runCli };
54
+ //# sourceMappingURL=cliRun.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cliRun.js","sources":["../src/cliRun.ts"],"sourcesContent":["import { resolve } from 'node:path'\n\nimport {\n cesiumBaseUrlScript,\n copyCesiumAssets,\n joinPublicPath,\n planCesiumAssets,\n} from './cesiumAssets'\n\nconst USAGE = 'Usage: xgis-cesium-assets copy <dir> [--base <name>] [--public-path <prefix>]'\n\nexport function runCli(argv: string[]): string {\n const [command, target, ...rest] = argv\n\n if (command !== 'copy') {\n throw new Error(`Unknown command: ${command ?? '(none)'}\\n${USAGE}`)\n }\n\n if (!target || target.startsWith('-')) {\n throw new Error(`Expected a target directory, got ${target ?? '(none)'}\\n${USAGE}`)\n }\n\n const plan = planCesiumAssets({ base: readFlag(rest, '--base') })\n const outDir = resolve(process.cwd(), target)\n\n copyCesiumAssets(plan, outDir)\n\n // Disk location says nothing about the served URL, so the prefix is given rather than guessed.\n const publicPath = joinPublicPath(readFlag(rest, '--public-path') ?? '/', plan.dir)\n\n return [\n `Copied ${plan.entries.length} Cesium asset directories and LICENSE.md to ${outDir}/${plan.dir}`,\n '',\n 'Add this to the <head> of your HTML, before any bundle script:',\n ` <script>${cesiumBaseUrlScript(publicPath)}</script>`,\n '',\n `If ${target} is not served at the site root, re-run with --public-path <prefix> to get the`,\n 'right value, or adjust the path above to match.',\n ].join('\\n')\n}\n\nfunction readFlag(args: string[], flag: string): string | undefined {\n const inline = args.find((arg) => arg.startsWith(`${flag}=`))\n\n if (inline) {\n return requireValue(inline.slice(flag.length + 1), flag)\n }\n\n const index = args.indexOf(flag)\n\n if (index === -1) {\n return undefined\n }\n\n const value = args[index + 1]\n\n if (value === undefined || value.startsWith('-')) {\n throw new Error(`${flag} needs a value\\n${USAGE}`)\n }\n\n return requireValue(value, flag)\n}\n\nfunction requireValue(value: string, flag: string): string {\n if (!value) {\n throw new Error(`${flag} needs a value\\n${USAGE}`)\n }\n\n return value\n}\n"],"names":[],"mappings":";;;AASA,MAAM,KAAA,GAAQ,+EAAA;AAEP,SAAS,OAAO,IAAA,EAAwB;AAC7C,EAAA,MAAM,CAAC,OAAA,EAAS,MAAA,EAAQ,GAAG,IAAI,CAAA,GAAI,IAAA;AAEnC,EAAA,IAAI,YAAY,MAAA,EAAQ;AACtB,IAAA,MAAM,IAAI,KAAA,CAAM,CAAA,iBAAA,EAAoB,OAAA,IAAW,QAAQ;AAAA,EAAK,KAAK,CAAA,CAAE,CAAA;AAAA,EACrE;AAEA,EAAA,IAAI,CAAC,MAAA,IAAU,MAAA,CAAO,UAAA,CAAW,GAAG,CAAA,EAAG;AACrC,IAAA,MAAM,IAAI,KAAA,CAAM,CAAA,iCAAA,EAAoC,MAAA,IAAU,QAAQ;AAAA,EAAK,KAAK,CAAA,CAAE,CAAA;AAAA,EACpF;AAEA,EAAA,MAAM,IAAA,GAAO,iBAAiB,EAAE,IAAA,EAAM,SAAS,IAAA,EAAM,QAAQ,GAAG,CAAA;AAChE,EAAA,MAAM,MAAA,GAAS,OAAA,CAAQ,OAAA,CAAQ,GAAA,IAAO,MAAM,CAAA;AAE5C,EAA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AAO,YAAA,CAAa,OAAO,IAAI,CAAA;AACjC;AAEA,SAAS,YAAA,CAAa,OAAe,IAAA,EAAsB;AACzD,EAAA,IAAI,CAAC,KAAA,EAAO;AACV,IAAA,MAAM,IAAI,KAAA,CAAM,CAAA,EAAG,IAAI,CAAA;AAAA,EAAmB,KAAK,CAAA,CAAE,CAAA;AAAA,EACnD;AAEA,EAAA,OAAO,KAAA;AACT;;;;"}
@@ -0,0 +1,17 @@
1
+ import type { Compiler } from '@rspack/core';
2
+ import type { CesiumAssetsOptions } from './cesiumAssets';
3
+ /**
4
+ * Copies Cesium's runtime assets (workers, textures, widget CSS) into the compilation output,
5
+ * serves them in dev, and injects `window.CESIUM_BASE_URL` into the HTML HtmlRspackPlugin emits.
6
+ */
7
+ export declare class CesiumAssetsRspackPlugin {
8
+ private readonly plan;
9
+ private copied;
10
+ constructor(options?: CesiumAssetsOptions);
11
+ apply(compiler: Compiler): void;
12
+ }
13
+ /**
14
+ * `output.publicPath` may be `'auto'` (a bundler marker, not a URL), `''` (deliberately relative to
15
+ * the document) or a function, which cannot be resolved before a compilation exists.
16
+ */
17
+ export declare function resolvePublicPath(configured: unknown, dir: string): string;
@@ -0,0 +1,71 @@
1
+ import { planCesiumAssets, copyCesiumAssets, cesiumBaseUrlScript, joinPublicPath } from './cesiumAssets.js';
2
+
3
+ const PLUGIN_NAME = "CesiumAssetsRspackPlugin";
4
+ class CesiumAssetsRspackPlugin {
5
+ plan;
6
+ copied = false;
7
+ constructor(options = {}) {
8
+ this.plan = planCesiumAssets(options);
9
+ }
10
+ apply(compiler) {
11
+ const publicPath = resolvePublicPath(compiler.options.output.publicPath, this.plan.dir);
12
+ const { HtmlRspackPlugin } = compiler.rspack;
13
+ compiler.options.devServer = {
14
+ ...compiler.options.devServer,
15
+ static: [
16
+ ...normaliseStatic(compiler.options.devServer?.static),
17
+ { directory: this.plan.source, publicPath: `/${this.plan.dir}` }
18
+ ]
19
+ };
20
+ compiler.hooks.afterEmit.tap(PLUGIN_NAME, () => {
21
+ if (this.copied) {
22
+ return;
23
+ }
24
+ copyCesiumAssets(this.plan, compiler.outputPath);
25
+ this.copied = true;
26
+ });
27
+ compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
28
+ if (!hasHtmlPlugin(compiler, HtmlRspackPlugin)) {
29
+ compilation.warnings.push(
30
+ new Error(
31
+ `${PLUGIN_NAME}: HtmlRspackPlugin is required to inject window.CESIUM_BASE_URL. Set it to "${publicPath}" yourself if you generate HTML another way.`
32
+ )
33
+ );
34
+ return;
35
+ }
36
+ HtmlRspackPlugin.getCompilationHooks(compilation).alterAssetTagGroups.tap(
37
+ PLUGIN_NAME,
38
+ (data) => {
39
+ data.headTags.unshift({
40
+ tagName: "script",
41
+ voidTag: false,
42
+ attributes: {},
43
+ innerHTML: cesiumBaseUrlScript(publicPath)
44
+ });
45
+ return data;
46
+ }
47
+ );
48
+ });
49
+ }
50
+ }
51
+ function hasHtmlPlugin(compiler, HtmlRspackPlugin) {
52
+ const plugins = compiler.options.plugins ?? [];
53
+ return plugins.some(
54
+ (plugin) => plugin instanceof HtmlRspackPlugin || plugin?.constructor?.name === "HtmlRspackPlugin"
55
+ );
56
+ }
57
+ function normaliseStatic(configured) {
58
+ if (configured === void 0 || typeof configured === "boolean") {
59
+ return [];
60
+ }
61
+ return Array.isArray(configured) ? [...configured] : [configured];
62
+ }
63
+ function resolvePublicPath(configured, dir) {
64
+ if (typeof configured === "function" || configured === void 0 || configured === "auto") {
65
+ return joinPublicPath("/", dir);
66
+ }
67
+ return joinPublicPath(String(configured), dir);
68
+ }
69
+
70
+ export { CesiumAssetsRspackPlugin, resolvePublicPath };
71
+ //# sourceMappingURL=rspack-plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rspack-plugin.js","sources":["../src/rspack-plugin.ts"],"sourcesContent":["import type { Compiler } from '@rspack/core'\n\nimport type { CesiumAssetPlan, CesiumAssetsOptions } from './cesiumAssets'\nimport {\n cesiumBaseUrlScript,\n copyCesiumAssets,\n joinPublicPath,\n planCesiumAssets,\n} from './cesiumAssets'\n\nconst PLUGIN_NAME = 'CesiumAssetsRspackPlugin'\n\n/**\n * Copies Cesium's runtime assets (workers, textures, widget CSS) into the compilation output,\n * serves them in dev, and injects `window.CESIUM_BASE_URL` into the HTML HtmlRspackPlugin emits.\n */\nexport class CesiumAssetsRspackPlugin {\n private readonly plan: CesiumAssetPlan\n\n private copied = false\n\n constructor(options: CesiumAssetsOptions = {}) {\n this.plan = planCesiumAssets(options)\n }\n\n apply(compiler: Compiler): void {\n const publicPath = resolvePublicPath(compiler.options.output.publicPath, this.plan.dir)\n // Off the compiler: getCompilationHooks rejects a compilation from a different instance.\n const { HtmlRspackPlugin } = compiler.rspack\n\n // The copy is on disk but the dev server serves from memory, so it needs the source directory.\n compiler.options.devServer = {\n ...compiler.options.devServer,\n static: [\n ...normaliseStatic(compiler.options.devServer?.static),\n { directory: this.plan.source, publicPath: `/${this.plan.dir}` },\n ],\n }\n\n // afterEmit fires per rebuild; the tree is tens of megabytes and never changes within a run.\n compiler.hooks.afterEmit.tap(PLUGIN_NAME, () => {\n if (this.copied) {\n return\n }\n\n copyCesiumAssets(this.plan, compiler.outputPath)\n this.copied = true\n })\n\n compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {\n // The hook exists even with no HTML plugin driving it, so absence is otherwise silent.\n if (!hasHtmlPlugin(compiler, HtmlRspackPlugin)) {\n compilation.warnings.push(\n new Error(\n `${PLUGIN_NAME}: HtmlRspackPlugin is required to inject window.CESIUM_BASE_URL. ` +\n `Set it to \"${publicPath}\" yourself if you generate HTML another way.`,\n ),\n )\n\n return\n }\n\n // First in <head> so it runs before any module, beating ensureCesiumBaseUrl()'s default.\n HtmlRspackPlugin.getCompilationHooks(compilation).alterAssetTagGroups.tap(\n PLUGIN_NAME,\n (data) => {\n data.headTags.unshift({\n tagName: 'script',\n voidTag: false,\n attributes: {},\n innerHTML: cesiumBaseUrlScript(publicPath),\n })\n\n return data\n },\n )\n })\n }\n}\n\nfunction hasHtmlPlugin(compiler: Compiler, HtmlRspackPlugin: unknown): boolean {\n const plugins = compiler.options.plugins ?? []\n\n return plugins.some(\n (plugin) =>\n plugin instanceof (HtmlRspackPlugin as new () => object) ||\n plugin?.constructor?.name === 'HtmlRspackPlugin',\n )\n}\n\ntype DevServerStatic = NonNullable<NonNullable<Compiler['options']['devServer']>['static']>\ntype StaticEntry = Extract<DevServerStatic, readonly unknown[]>[number]\n\n// `static` accepts a single entry, an array, or a boolean; only the first two carry entries to keep.\nfunction normaliseStatic(configured: DevServerStatic | undefined): StaticEntry[] {\n if (configured === undefined || typeof configured === 'boolean') {\n return []\n }\n\n return Array.isArray(configured) ? [...configured] : [configured as StaticEntry]\n}\n\n/**\n * `output.publicPath` may be `'auto'` (a bundler marker, not a URL), `''` (deliberately relative to\n * the document) or a function, which cannot be resolved before a compilation exists.\n */\nexport function resolvePublicPath(configured: unknown, dir: string): string {\n if (typeof configured === 'function' || configured === undefined || configured === 'auto') {\n return joinPublicPath('/', dir)\n }\n\n return joinPublicPath(String(configured), dir)\n}\n"],"names":[],"mappings":";;AAUA,MAAM,WAAA,GAAc,0BAAA;AAMb,MAAM,wBAAA,CAAyB;AAAA,EACnB,IAAA;AAAA,EAET,MAAA,GAAS,KAAA;AAAA,EAEjB,WAAA,CAAY,OAAA,GAA+B,EAAC,EAAG;AAC7C,IAAA,IAAA,CAAK,IAAA,GAAO,iBAAiB,OAAO,CAAA;AAAA,EACtC;AAAA,EAEA,MAAM,QAAA,EAA0B;AAC9B,IAAA,MAAM,UAAA,GAAa,kBAAkB,QAAA,CAAS,OAAA,CAAQ,OAAO,UAAA,EAAY,IAAA,CAAK,KAAK,GAAG,CAAA;AAEtF,IAAA,MAAM,EAAE,gBAAA,EAAiB,GAAI,QAAA,CAAS,MAAA;AAGtC,IAAA,QAAA,CAAS,QAAQ,SAAA,GAAY;AAAA,MAC3B,GAAG,SAAS,OAAA,CAAQ,SAAA;AAAA,MACpB,M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ACH;AACF;AAEA,SAAS,aAAA,CAAc,UAAoB,gBAAA,EAAoC;AAC7E,EAAA,MAAM,OAAA,GAAU,QAAA,CAAS,OAAA,CAAQ,OAAA,IAAW,EAAC;AAE7C,EAAA,OAAO,OAAA,CAAQ,IAAA;AAAA,IACb,CAAC,MAAA,KACC,MAAA,YAAmB,gBAAA,IACnB,MAAA,EAAQ,aAAa,IAAA,KAAS;AAAA,GAClC;AACF;AAMA,SAAS,gBAAgB,UAAA,EAAwD;AAC/E,EAAA,IAAI,UAAA,KAAe,MAAA,IAAa,OAAO,UAAA,KAAe,SAAA,EAAW;AAC/D,IAAA,OAAO,EAAC;AAAA,EACV;AAEA,EAAA,OAAO,KAAA,CAAM,QAAQ,UAAU,CAAA,GAAI,CAAC,GAAG,UAAU,CAAA,GAAI,CAAC,UAAyB,CAAA;AACjF;AAMO,SAAS,iBAAA,CAAkB,YAAqB,GAAA,EAAqB;AAC1E,EAAA,IAAI,OAAO,UAAA,KAAe,UAAA,IAAc,UAAA,KAAe,MAAA,IAAa,eAAe,MAAA,EAAQ;AACzF,IAAA,OAAO,cAAA,CAAe,KAAK,GAAG,CAAA;AAAA,EAChC;AAEA,EAAA,OAAO,cAAA,CAAe,MAAA,CAAO,UAAU,CAAA,EAAG,GAAG,CAAA;AAC/C;;;;"}
@@ -0,0 +1,8 @@
1
+ import type { Plugin } from 'vite';
2
+ import type { CesiumAssetsOptions } from './cesiumAssets';
3
+ export type { CesiumAssetsOptions };
4
+ /**
5
+ * Serves Cesium's runtime assets (workers, textures, widget CSS) in dev and copies them into a
6
+ * version-prefixed directory on build, so the directory can be cached immutably.
7
+ */
8
+ export declare function cesiumAssets(options?: CesiumAssetsOptions): Plugin;
@@ -0,0 +1,40 @@
1
+ import { resolve } from 'node:path';
2
+ import sirv from 'sirv';
3
+ import { planCesiumAssets, copyCesiumAssets, cesiumBaseUrlScript, joinPublicPath } from './cesiumAssets.js';
4
+
5
+ function devMountPath(publicPath) {
6
+ const origin = /^[a-z][a-z0-9+.-]*:\/\/[^/]*/i.exec(publicPath)?.[0] ?? "";
7
+ const path = publicPath.slice(origin.length);
8
+ return path.startsWith("/") ? path : `/${path}`;
9
+ }
10
+ function cesiumAssets(options = {}) {
11
+ const plan = planCesiumAssets(options);
12
+ let outDir;
13
+ let publicPath;
14
+ return {
15
+ name: "cesium-assets",
16
+ configResolved(config) {
17
+ outDir = resolve(config.root, config.build.outDir);
18
+ publicPath = joinPublicPath(config.base, plan.dir);
19
+ },
20
+ configureServer(server) {
21
+ server.middlewares.use(devMountPath(publicPath), sirv(plan.source, { dev: true }));
22
+ },
23
+ // In <head> so it runs before any module, beating ensureCesiumBaseUrl()'s default.
24
+ transformIndexHtml() {
25
+ return [
26
+ {
27
+ tag: "script",
28
+ injectTo: "head-prepend",
29
+ children: cesiumBaseUrlScript(publicPath)
30
+ }
31
+ ];
32
+ },
33
+ writeBundle() {
34
+ copyCesiumAssets(plan, outDir);
35
+ }
36
+ };
37
+ }
38
+
39
+ export { cesiumAssets };
40
+ //# sourceMappingURL=vite-plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vite-plugin.js","sources":["../src/vite-plugin.ts"],"sourcesContent":["import { resolve } from 'node:path'\n\nimport sirv from 'sirv'\nimport type { Plugin, ResolvedConfig } from 'vite'\n\nimport type { CesiumAssetsOptions } from './cesiumAssets'\nimport {\n cesiumBaseUrlScript,\n copyCesiumAssets,\n joinPublicPath,\n planCesiumAssets,\n} from './cesiumAssets'\n\nexport type { CesiumAssetsOptions }\n\n// Runs before Vite strips `base`, so the mount has to carry it. A CDN base has no local path.\nfunction devMountPath(publicPath: string): string {\n const origin = /^[a-z][a-z0-9+.-]*:\\/\\/[^/]*/i.exec(publicPath)?.[0] ?? ''\n const path = publicPath.slice(origin.length)\n\n return path.startsWith('/') ? path : `/${path}`\n}\n\n/**\n * Serves Cesium's runtime assets (workers, textures, widget CSS) in dev and copies them into a\n * version-prefixed directory on build, so the directory can be cached immutably.\n */\nexport function cesiumAssets(options: CesiumAssetsOptions = {}): Plugin {\n const plan = planCesiumAssets(options)\n\n let outDir: string\n let publicPath: string\n\n return {\n name: 'cesium-assets',\n configResolved(config: ResolvedConfig) {\n outDir = resolve(config.root, config.build.outDir)\n // Without the base prefix a path-deployed app 404s every worker while the globe still renders.\n publicPath = joinPublicPath(config.base, plan.dir)\n },\n configureServer(server) {\n server.middlewares.use(devMountPath(publicPath), sirv(plan.source, { dev: true }))\n },\n // In <head> so it runs before any module, beating ensureCesiumBaseUrl()'s default.\n transformIndexHtml() {\n return [\n {\n tag: 'script',\n injectTo: 'head-prepend',\n children: cesiumBaseUrlScript(publicPath),\n },\n ]\n },\n writeBundle() {\n copyCesiumAssets(plan, outDir)\n },\n }\n}\n"],"names":[],"mappings":";;;;AAgBA,SAAS,aAAa,UAAA,EAA4B;AAChD,EAAA,MAAM,SAAS,+BAAA,CAAgC,IAAA,CAAK,UAAU,CAAA,GAAI,CAAC,CAAA,IAAK,EAAA;AACxE,EAAA,MAAM,IAAA,GAAO,UAAA,CAAW,KAAA,CAAM,MAAA,CAAO,MAAM,CAAA;AAE3C,EAAA,OAAO,KAAK,UAAA,CAAW,GAAG,CAAA,GAAI,IAAA,GAAO,IAAI,IAAI,CAAA,CAAA;AAC/C;AAMO,SAAS,YAAA,CAAa,OAAA,GAA+B,EAAC,EAAW;AACtE,EAAA,MAAM,IAAA,GAAO,iBAAiB,OAAO,CAAA;AAErC,EAAA,IAAI,MAAA;AACJ,EAAA,IAAI,UAAA;AAEJ,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,eAAA;AAAA,IACN,eAAe,MAAA,EAAwB;AACrC,MAAA,MAAA,GAAS,OAAA,CAAQ,MAAA,CAAO,IAAA,EAAM,MAAA,CAAO,MAAM,MAAM,CAAA;AAEjD,MAAA,UAAA,GAAa,cAAA,CAAe,MAAA,CAAO,IAAA,EAAM,IAAA,CAAK,GAAG,CAAA;AAAA,IACnD,CAAA;AAAA,IACA,gBAAgB,MAAA,EAAQ;AACtB,MAAA,MAAA,CAAO,WAAA,CAAY,GAAA,CAAI,YAAA,CAAa,UAAU,CAAA,EAAG,IAAA,CAAK,IAAA,CAAK,MAAA,EAAQ,EAAE,GAAA,EAAK,IAAA,EAAM,CAAC,CAAA;AAAA,IACnF,CAAA;AAAA;AAAA,IAEA,kBAAA,GAAqB;AACnB,MAAA,OAAO;AAAA,QACL;AAAA,UACE,GAAA,EAAK,QAAA;AAAA,UACL,QAAA,EAAU,cAAA;AAAA,UACV,QAAA,EAAU,oBAAoB,UAAU;AAAA;AAC1C,OACF;AAAA,IACF,CAAA;AAAA,IACA,WAAA,GAAc;AACZ,MAAA,gBAAA,CAAiB,MAAM,MAAM,CAAA;AAAA,IAC/B;AAAA,GACF;AACF;;;;"}
package/package.json ADDED
@@ -0,0 +1,67 @@
1
+ {
2
+ "name": "@xgis/xgis3d-build",
3
+ "version": "0.3.23",
4
+ "description": "Build-tool integration for @xgis/xgis3d — serves and copies CesiumJS runtime assets.",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "files": [
8
+ "dist",
9
+ "bin"
10
+ ],
11
+ "bin": {
12
+ "xgis-cesium-assets": "./bin/xgis-cesium-assets.mjs"
13
+ },
14
+ "exports": {
15
+ ".": {
16
+ "types": "./dist/cesiumAssets.d.ts",
17
+ "import": "./dist/cesiumAssets.js"
18
+ },
19
+ "./vite": {
20
+ "types": "./dist/vite-plugin.d.ts",
21
+ "import": "./dist/vite-plugin.js"
22
+ },
23
+ "./rspack": {
24
+ "types": "./dist/rspack-plugin.d.ts",
25
+ "import": "./dist/rspack-plugin.js"
26
+ }
27
+ },
28
+ "publishConfig": {
29
+ "access": "public"
30
+ },
31
+ "peerDependencies": {
32
+ "@rspack/core": "^1.0.0",
33
+ "vite": "^6.0.0 || ^7.0.0",
34
+ "@xgis/xgis3d": "^0.3.23"
35
+ },
36
+ "peerDependenciesMeta": {
37
+ "@rspack/core": {
38
+ "optional": true
39
+ },
40
+ "vite": {
41
+ "optional": true
42
+ }
43
+ },
44
+ "dependencies": {
45
+ "sirv": "^3.0.2"
46
+ },
47
+ "devDependencies": {
48
+ "@rspack/core": "^1.7.12",
49
+ "@types/node": "^22.10.2",
50
+ "@vitest/coverage-v8": "^4.1.7",
51
+ "typescript": "^6.0.3",
52
+ "vite": "^6.4.3",
53
+ "vitest": "^4.1.7",
54
+ "@xgis/tsconfig": "0.0.0",
55
+ "@xgis/xgis3d": "0.3.23",
56
+ "@xgis/eslint-config": "0.0.0"
57
+ },
58
+ "scripts": {
59
+ "lint": "eslint src",
60
+ "typecheck": "tsc --noEmit",
61
+ "test": "vitest run",
62
+ "test:coverage": "vitest run --coverage",
63
+ "build:lib": "vite build --config vite.lib.config.ts && tsc -p tsconfig.build.json"
64
+ },
65
+ "main": "./dist/cesiumAssets.js",
66
+ "types": "./dist/cesiumAssets.d.ts"
67
+ }