earthsdk3-assets 3.1.0-beta.1 → 3.1.1

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "earthsdk3-assets",
3
- "version": "3.1.0-beta.1",
3
+ "version": "3.1.1",
4
4
  "description": "地球可视化实验室 (EarthSDK&CesiumLab) https://www.bjxbsj.cn",
5
5
  "private": false,
6
6
  "type": "module",
@@ -54,8 +54,21 @@ export default function earthsdkAssetsVite(options = {}) {
54
54
 
55
55
  configureServer(server) {
56
56
  server.middlewares.use(`/${assetsPath}`, (req, res, next) => {
57
- const urlPath = decodeURIComponent(req.url);
58
- const filePath = path.join(ROOT_DIR, urlPath === '/' ? 'earthsdk3-assets.js' : urlPath.slice(1));
57
+ // 去除 query 参数,避免 ?v=xxx 等缓存处理导致文件找不到
58
+ const urlPath = decodeURIComponent(req.url).split('?')[0];
59
+ // 去掉 /earthsdk3-assets 前缀,得到相对于 ROOT_DIR 的路径
60
+ const prefix = `/${assetsPath}`;
61
+ let relPath;
62
+ if (urlPath.startsWith(prefix + '/')) {
63
+ // /earthsdk3-assets/assets/img/... → assets/img/...
64
+ relPath = urlPath.slice(prefix.length + 1);
65
+ } else if (urlPath === prefix || urlPath === prefix + '/') {
66
+ relPath = 'earthsdk3-assets.js';
67
+ } else {
68
+ // /earthsdk3-assets.js 等,保留原始行为
69
+ relPath = urlPath.slice(1);
70
+ }
71
+ const filePath = path.join(ROOT_DIR, relPath);
59
72
 
60
73
  if (!fs.existsSync(filePath)) {
61
74
  return next();