From 85e4c5548a11e8248460e5ff2feef9810dd02156 Mon Sep 17 00:00:00 2001 From: rot1024 Date: Mon, 5 Aug 2024 16:43:54 +0900 Subject: [PATCH 1/2] feat: cesiumBaseUrl option --- src/index.ts | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/index.ts b/src/index.ts index f7a3de2..e2e0290 100644 --- a/src/index.ts +++ b/src/index.ts @@ -12,6 +12,7 @@ interface VitePluginCesiumOptions { devMinifyCesium?: boolean; cesiumBuildRootPath?: string; cesiumBuildPath?: string; + cesiumBaseUrl?: string; } export default function vitePluginCesium(options: VitePluginCesiumOptions = {}): Plugin { @@ -19,10 +20,14 @@ export default function vitePluginCesium(options: VitePluginCesiumOptions = {}): rebuildCesium = false, devMinifyCesium = false, cesiumBuildRootPath = 'node_modules/cesium/Build', - cesiumBuildPath = 'node_modules/cesium/Build/Cesium/' + cesiumBuildPath = 'node_modules/cesium/Build/Cesium/', + cesiumBaseUrl = 'cesium/' } = options; - let CESIUM_BASE_URL = 'cesium/'; + let CESIUM_BASE_URL = cesiumBaseUrl; + if (!CESIUM_BASE_URL.endsWith('/')) { + CESIUM_BASE_URL += '/'; + } let outDir = 'dist'; let base: string = '/'; let isBuild: boolean = false; @@ -59,7 +64,7 @@ export default function vitePluginCesium(options: VitePluginCesiumOptions = {}): chunkSizeWarningLimit: 5000, rollupOptions: { output: { - intro: `window.CESIUM_BASE_URL = "${CESIUM_BASE_URL}";` + intro: `window.CESIUM_BASE_URL = ${JSON.stringify(CESIUM_BASE_URL)};` } } }; @@ -88,12 +93,12 @@ export default function vitePluginCesium(options: VitePluginCesiumOptions = {}): async closeBundle() { if (isBuild) { try { - await fs.copy(path.join(cesiumBuildPath, 'Assets'), path.join(outDir, 'cesium/Assets')); - await fs.copy(path.join(cesiumBuildPath, 'ThirdParty'), path.join(outDir, 'cesium/ThirdParty')); - await fs.copy(path.join(cesiumBuildPath, 'Workers'), path.join(outDir, 'cesium/Workers')); - await fs.copy(path.join(cesiumBuildPath, 'Widgets'), path.join(outDir, 'cesium/Widgets')); + await fs.copy(path.join(cesiumBuildPath, 'Assets'), path.join(outDir, CESIUM_BASE_URL, 'Assets')); + await fs.copy(path.join(cesiumBuildPath, 'ThirdParty'), path.join(outDir, CESIUM_BASE_URL, 'ThirdParty')); + await fs.copy(path.join(cesiumBuildPath, 'Workers'), path.join(outDir, CESIUM_BASE_URL, 'Workers')); + await fs.copy(path.join(cesiumBuildPath, 'Widgets'), path.join(outDir, CESIUM_BASE_URL, 'Widgets')); if (!rebuildCesium) { - await fs.copy(path.join(cesiumBuildPath, 'Cesium.js'), path.join(outDir, 'cesium/Cesium.js')); + await fs.copy(path.join(cesiumBuildPath, 'Cesium.js'), path.join(outDir, CESIUM_BASE_URL, 'Cesium.js')); } } catch (err) { console.error('copy failed', err); From 1a0f2e4a426e0dbcedb470d543f2458d967bf456 Mon Sep 17 00:00:00 2001 From: rot1024 Date: Tue, 6 Aug 2024 18:52:29 +0900 Subject: [PATCH 2/2] avoid ci error in node16 --- demo/package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/demo/package.json b/demo/package.json index 724a9ea..62036b1 100644 --- a/demo/package.json +++ b/demo/package.json @@ -9,8 +9,8 @@ "serve": "vite build && vite preview" }, "devDependencies": { - "cesium": "^1.96.0", - "vite": "^3.0.4", + "cesium": "1.96.0", + "vite": "3.0.4", "vite-plugin-cesium": "link:.." } }