cesium-xs-sdk 1.0.3 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/vite-plugin.js +19 -2
package/package.json
CHANGED
package/src/vite-plugin.js
CHANGED
|
@@ -15,8 +15,10 @@
|
|
|
15
15
|
import fs from 'fs';
|
|
16
16
|
import path from 'path';
|
|
17
17
|
import { fileURLToPath } from 'url';
|
|
18
|
+
import { createRequire } from 'module';
|
|
18
19
|
|
|
19
20
|
const __filename = fileURLToPath(import.meta.url);
|
|
21
|
+
const require = createRequire(import.meta.url);
|
|
20
22
|
|
|
21
23
|
const CONTENT_TYPE_MAP = {
|
|
22
24
|
'.js': 'application/javascript',
|
|
@@ -59,8 +61,14 @@ function resolveCesiumRoot(userRoot) {
|
|
|
59
61
|
if (userRoot) {
|
|
60
62
|
return path.resolve(userRoot);
|
|
61
63
|
}
|
|
62
|
-
//
|
|
63
|
-
|
|
64
|
+
// 优先用 Node 模块解析,支持 monorepo / workspace / pnpm 等 hoist 场景
|
|
65
|
+
try {
|
|
66
|
+
const pkgJsonPath = require.resolve('cesium/package.json');
|
|
67
|
+
return path.dirname(pkgJsonPath);
|
|
68
|
+
} catch (e) {
|
|
69
|
+
console.warn('[cesium-xs-sdk/vite] 无法通过 require.resolve 定位 cesium,回退到当前工作目录 node_modules');
|
|
70
|
+
return path.resolve(process.cwd(), 'node_modules/cesium');
|
|
71
|
+
}
|
|
64
72
|
}
|
|
65
73
|
|
|
66
74
|
function normalizeBaseUrl(url) {
|
|
@@ -95,6 +103,14 @@ export function cesiumXsSdkPlugin(options = {}) {
|
|
|
95
103
|
}
|
|
96
104
|
};
|
|
97
105
|
},
|
|
106
|
+
configResolved() {
|
|
107
|
+
if (!fs.existsSync(cesiumBuildPath)) {
|
|
108
|
+
console.warn(
|
|
109
|
+
`[cesium-xs-sdk/vite] 未找到 Cesium 构建目录: ${cesiumBuildPath}\n` +
|
|
110
|
+
`请确认已安装 cesium,或在插件选项中指定 cesiumPackageRoot。`
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
},
|
|
98
114
|
configureServer(server) {
|
|
99
115
|
server.middlewares.use((req, res, next) => {
|
|
100
116
|
if (!req.url || !req.url.startsWith(cesiumBaseUrl)) {
|
|
@@ -113,6 +129,7 @@ export function cesiumXsSdkPlugin(options = {}) {
|
|
|
113
129
|
return;
|
|
114
130
|
}
|
|
115
131
|
|
|
132
|
+
console.warn(`[cesium-xs-sdk/vite] 未找到 Cesium 资源: ${filePath} (请求: ${req.url})`);
|
|
116
133
|
next();
|
|
117
134
|
});
|
|
118
135
|
},
|