From 7ae01a714a7b9d716eb9145b439ab21b742825b4 Mon Sep 17 00:00:00 2001 From: Brice Schaffner Date: Tue, 10 Dec 2024 07:23:53 +0100 Subject: [PATCH] PB-1176: Fix cesium static assets location During the build the cesium static assets were put into the root of the application. This was an issue for our deployment strategy were we have all assets in a versioned folder and were we first deploy the versioned folder before deploying the entry point index.html that point to the versioned folder. This allow for a pseudo atomic deployment. So now all the cesium static assets have been placed into VERSION/cesium/ path. --- .eslintrc.cjs | 1 + src/config/map.config.js | 7 +++++++ src/modules/map/components/cesium/CesiumMap.vue | 4 ++-- vite.config.mts | 10 ++++++---- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 9ef67e2b7..66598d589 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -35,6 +35,7 @@ module.exports = { globals: { VITE_ENVIRONMENT: true, __APP_VERSION__: true, + __CESIUM_STATIC_PATH__: true, defineModel: 'readonly', }, overrides: [ diff --git a/src/config/map.config.js b/src/config/map.config.js index 2be7b5820..602b7abc2 100644 --- a/src/config/map.config.js +++ b/src/config/map.config.js @@ -77,3 +77,10 @@ export const DEFAULT_FEATURE_COUNT_RECTANGLE_SELECTION = 50 * @type {Number} */ export const GPX_GEOMETRY_SIMPLIFICATION_TOLERANCE = 12.5 // meters + +/** + * Path to the cesium static assets + * + * @type {string} + */ +export const CESIUM_STATIC_PATH = __CESIUM_STATIC_PATH__ diff --git a/src/modules/map/components/cesium/CesiumMap.vue b/src/modules/map/components/cesium/CesiumMap.vue index 1f8e3791f..a75b88baf 100644 --- a/src/modules/map/components/cesium/CesiumMap.vue +++ b/src/modules/map/components/cesium/CesiumMap.vue @@ -74,7 +74,7 @@ import GeoAdminGeoJsonLayer from '@/api/layers/GeoAdminGeoJsonLayer.class' import GPXLayer from '@/api/layers/GPXLayer.class' import KMLLayer from '@/api/layers/KMLLayer.class' import { get3dTilesBaseUrl, getWmsBaseUrl, getWmtsBaseUrl } from '@/config/baseUrl.config' -import { DEFAULT_PROJECTION } from '@/config/map.config' +import { CESIUM_STATIC_PATH, DEFAULT_PROJECTION } from '@/config/map.config' import { IS_TESTING_WITH_CYPRESS } from '@/config/staging.config' import FeatureEdit from '@/modules/infobox/components/FeatureEdit.vue' import FeatureList from '@/modules/infobox/components/FeatureList.vue' @@ -207,7 +207,7 @@ export default { beforeCreate() { // Global variable required for Cesium and point to the URL where four static directories (see vite.config) are served // https://cesium.com/learn/cesiumjs-learn/cesiumjs-quickstart/#install-with-npm - window['CESIUM_BASE_URL'] = '.' + window['CESIUM_BASE_URL'] = CESIUM_STATIC_PATH // required for ol-cesium window['Cesium'] = cesium diff --git a/vite.config.mts b/vite.config.mts index d2a1b53e9..897bc8ebd 100644 --- a/vite.config.mts +++ b/vite.config.mts @@ -21,6 +21,7 @@ if (!appVersion) { const __dirname = dirname(fileURLToPath(import.meta.url)) const cesiumSource = `${__dirname}/node_modules/cesium/Source` const cesiumWorkers = '../Build/Cesium/Workers' +const cesiumStaticDir = `./${appVersion}/cesium/` /** * We use manual chunks to reduce the size of the final index.js file to improve startup @@ -79,19 +80,19 @@ export default defineConfig(({ mode }) => { targets: [ { src: normalizePath(`${cesiumSource}/${cesiumWorkers}`), - dest: `./`, + dest: cesiumStaticDir, }, { src: normalizePath(`${cesiumSource}/Assets/`), - dest: `./`, + dest: cesiumStaticDir, }, { src: normalizePath(`${cesiumSource}/Widgets/`), - dest: `./`, + dest: cesiumStaticDir, }, { src: normalizePath(`${cesiumSource}/ThirdParty/`), - dest: `./`, + dest: cesiumStaticDir, }, ], }), @@ -106,6 +107,7 @@ export default defineConfig(({ mode }) => { define: { __APP_VERSION__: JSON.stringify(appVersion), VITE_ENVIRONMENT: JSON.stringify(mode), + __CESIUM_STATIC_PATH__: JSON.stringify(cesiumStaticDir), }, test: { include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],