UNPKG

vite-plugin-cesium-build

Version:
73 lines (66 loc) 1.84 kB
'use strict'; const pathe = require('pathe'); function isString(val) { return typeof val === "string"; } function imports(pathList, apply) { let base; return { name: `vite-plugin-cesium-build:imports${isString(apply) ? `:${apply}` : ""}`, apply, configResolved(resolvedConfig) { base = resolvedConfig.base; }, transformIndexHtml: () => pathList.map((_path) => { const path = _path(base); return path.endsWith(".js") ? { tag: "script", attrs: { ...apply === "build" ? { crossorigin: true } : {}, src: path } } : path.endsWith(".css") ? { tag: "link", attrs: { rel: "stylesheet", ...apply === "build" ? { crossorigin: true } : {}, href: path } } : null; }).filter(Boolean) }; } function resolveOptions(userOptions = {}, defaultFrom) { const defaultOptions = { from: defaultFrom, to: "cesium-package", customCesiumBaseUrl: false, css: false, iife: true }; return { ...defaultOptions, ...userOptions }; } function setBaseUrl(options) { const { customCesiumBaseUrl, to } = options; let base; if (customCesiumBaseUrl === true) throw new Error("[vite-plugin-cesium-build[internal error]]: customCesiumBaseUrl should not be true in `setBaseUrl`"); return { name: "vite-plugin-cesium-build:setBaseUrl", configResolved(resolvedConfig) { base = resolvedConfig.base; }, transformIndexHtml: () => [ { tag: "script", children: `Object.defineProperty(globalThis, 'CESIUM_BASE_URL', { value: '${isString(customCesiumBaseUrl) ? customCesiumBaseUrl : pathe.join(base, to, "/")}' })` } ] }; } exports.imports = imports; exports.resolveOptions = resolveOptions; exports.setBaseUrl = setBaseUrl;