Skip to content

Commit

Permalink
Merge pull request #55 from rot1024/main
Browse files Browse the repository at this point in the history
add cesiumBaseUrl option
  • Loading branch information
nshen authored Aug 6, 2024
2 parents 81e6e35 + 1a0f2e4 commit dddac6c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
4 changes: 2 additions & 2 deletions demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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:.."
}
}
21 changes: 13 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,22 @@ interface VitePluginCesiumOptions {
devMinifyCesium?: boolean;
cesiumBuildRootPath?: string;
cesiumBuildPath?: string;
cesiumBaseUrl?: string;
}

export default function vitePluginCesium(options: VitePluginCesiumOptions = {}): Plugin {
const {
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;
Expand Down Expand Up @@ -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)};`
}
}
};
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit dddac6c

Please sign in to comment.