diff --git a/package.json b/package.json index 8a7d9d6..2027d9b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vite-plugin-earth", - "version": "2.1.1", + "version": "2.1.2", "description": "Cesium & Mars3D library plugin for Vite", "main": "./dist/index.js", "module": "./dist/index.mjs", @@ -37,7 +37,7 @@ }, "dependencies": { "fs-extra": "^9.1.0", - "rollup-plugin-external-globals": "^0.6.1", + "rollup-plugin-external-globals": "^0.8.0", "serve-static": "^1.14.1" }, "devDependencies": { @@ -48,7 +48,7 @@ "prettier": "^2.2.1", "tsup": "^6.2.1", "typescript": "^4.2.2", - "vite": "^4.3.4" + "vite": "^4.3.9" }, "peerDependencies": { "vite": ">=2.7.1" diff --git a/src/index.ts b/src/index.ts index 7c0dc44..84016e3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -90,16 +90,16 @@ export function mars3dPlugin(options: VitePluginMars3dOptions = {}): Plugin { }; } else { // build 2) copy Cesium.js later - let external = [CESIUM_NAME]; - let plugins = [externalGlobals({ cesium: 'Cesium' })]; - - external.push('mars3d'); - plugins.push(externalGlobals({ mars3d: 'mars3d' })); + const external = [CESIUM_NAME, 'mars3d']; + const globalsLibs = { + mars3d: 'mars3d', + 'mars3d-cesium': 'Cesium' + }; userConfig.build = { rollupOptions: { external: external, - plugins: plugins + plugins: [externalGlobals(globalsLibs)] } }; } @@ -187,10 +187,15 @@ export function mars3dPlugin(options: VitePluginMars3dOptions = {}): Plugin { } }); if (isBuild && !rebuildCesium) { + tags.push({ + tag: 'script', + children: `window['CESIUM_BASE_URL'] = '${CESIUM_BASE_URL}'` + }); + tags.push({ tag: 'script', attrs: { - src: normalizePath(path.join(base, `${CESIUM_NAME}/Cesium.js`)) + src: normalizePath(path.join(CESIUM_BASE_URL, `Cesium.js`)) } }); } @@ -203,7 +208,7 @@ export function mars3dPlugin(options: VitePluginMars3dOptions = {}): Plugin { } }); - if (isBuild && !rebuildCesium) { + if (isBuild) { tags.push({ tag: 'script', attrs: {