Skip to content

Commit

Permalink
fix: no need to change baseUrl on dev or prod.
Browse files Browse the repository at this point in the history
  • Loading branch information
s3xysteak committed May 15, 2024
1 parent 476f5d9 commit 1feeae8
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 28 deletions.
17 changes: 4 additions & 13 deletions src/core/setBaseUrl.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import type { Plugin, ResolvedConfig } from 'vite'
import type { BuildCesiumOptions } from './resolveOptions'
import { isString } from './utils'

export function setBaseUrl(options: BuildCesiumOptions, path: (base: string) => string, apply?: Plugin['apply']): Plugin {
const { customCesiumBaseUrl } = options
export function setBaseUrl(options: BuildCesiumOptions): Plugin {
const { customCesiumBaseUrl, to } = options
let base: ResolvedConfig['base']

return {
name: `vite-plugin-cesium-build:setBaseUrl${isString(apply) ? `:${apply}` : ''}`,
apply,
name: 'vite-plugin-cesium-build:setBaseUrl',
configResolved(resolvedConfig) {
base = resolvedConfig.base
},
Expand All @@ -17,15 +15,8 @@ export function setBaseUrl(options: BuildCesiumOptions, path: (base: string) =>
: () => [
{
tag: 'script',
children: `Object.defineProperty(globalThis, 'CESIUM_BASE_URL', { value: ${toUrlValue(customCesiumBaseUrl, path(base))} })`,
children: `Object.defineProperty(globalThis, 'CESIUM_BASE_URL', { value: ${base}${to}/ })`,
},
],
}
}

export function toUrlValue(
src: BuildCesiumOptions['customCesiumBaseUrl'],
str: string,
) {
return `'${isString(src) ? src : str}'`
}
2 changes: 1 addition & 1 deletion src/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function pluginEntry(pluginOptions?: Partial<BuildCesiumOptions>): Plugin[] {
},
],
),
setBaseUrl(options, base => `${base}${options.to}/`),
setBaseUrl(options),
]
}

Expand Down
5 changes: 2 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ function pluginEntry(pluginOptions?: Partial<BuildCesiumOptions>): Plugin[] {
),

importCesium(() => 'node_modules/cesium/Build/CesiumUnminified/Cesium.js', 'serve'),
setBaseUrl(options, () => 'node_modules/cesium/Build/CesiumUnminified/Cesium.js', 'serve'),

importCesium(base => `${base}${options.to}/Cesium.js`, 'build'),
setBaseUrl(options, base => `${base}${options.to}/`, 'build'),

setBaseUrl(options),
]
}

Expand Down
11 changes: 0 additions & 11 deletions test/setBaseUrl.test.ts

This file was deleted.

0 comments on commit 1feeae8

Please sign in to comment.