Skip to content

Commit

Permalink
feat!: Support @cesium/engine.
Browse files Browse the repository at this point in the history
This is a feature completely independent of `cesium` support, and has no impact on regular `cesium` users. As this is a major update, it is considered a BREAKING CHANGE.
For `@cesium/engine` users, this plugin can be used by `import cesium from 'vite-plugin-cesium-build/engine'`, and the usage is identical to `import cesium from 'vite-plugin-cesium-build'`.

Refs: #6
  • Loading branch information
s3xysteak committed Apr 7, 2024
1 parent 0437df8 commit 85df1de
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 5 deletions.
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
"types": "./dist/cesium.d.ts",
"import": "./dist/cesium.mjs",
"require": "./dist/cesium.cjs"
},
"./engine": {
"types": "./dist/engine.d.ts",
"import": "./dist/engine.mjs",
"require": "./dist/engine.cjs"
}
},
"main": "./dist/cesium.cjs",
Expand Down
6 changes: 1 addition & 5 deletions src/core/setBaseUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@ export function setBaseUrl(options: BuildCesiumOptions): Plugin {
: () => [
{
tag: 'script',
children: `Object.defineProperty(
globalThis,
'CESIUM_BASE_URL',
{ value: ${toUrlValue(customCesiumBaseUrl, { base, to })} }
)`,
children: `Object.defineProperty(globalThis, 'CESIUM_BASE_URL', { value: ${toUrlValue(customCesiumBaseUrl, { base, to })} })`,
},
],
}
Expand Down
33 changes: 33 additions & 0 deletions src/engine.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import type { Plugin } from 'vite'

import { setBaseUrl } from './core/setBaseUrl'
import { type BuildCesiumOptions, resolveOptions } from './core/resolveOptions'
import { copyCesium } from './core/copyCesium'

function pluginEntry(pluginOptions?: Partial<BuildCesiumOptions>): Plugin[] {
const options = resolveOptions(pluginOptions, 'node_modules/@cesium/engine')

return [
...copyCesium(
options,
[],
[
{
src: `${options.from}/Source/Assets/*`,
dest: `${options.to}/Assets/`,
},
{
src: `${options.from}/Build/ThirdParty/*`,
dest: `${options.to}/ThirdParty/`,
},
{
src: `${options.from}/Build/Workers/*`,
dest: `${options.to}/Workers/`,
},
],
),
setBaseUrl(options),
]
}

export default pluginEntry

0 comments on commit 85df1de

Please sign in to comment.