From 842b5ec25a0f05b63d2dc4428121d2160837cc24 Mon Sep 17 00:00:00 2001 From: LiuJiaNan <15703339975@163.com> Date: Tue, 6 Jan 2026 15:20:10 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .claude/settings.local.json | 3 ++- package.json | 2 +- rollup.config.js | 39 ++++++++++++++++++++++++++++----- src/components/Map/CesiumMap.js | 2 +- 4 files changed, 37 insertions(+), 9 deletions(-) diff --git a/.claude/settings.local.json b/.claude/settings.local.json index fabfc00..b74d265 100644 --- a/.claude/settings.local.json +++ b/.claude/settings.local.json @@ -7,7 +7,8 @@ "Bash(tree:*)", "Bash(cat:*)", "Bash(git rm:*)", - "Bash(git check-ignore:*)" + "Bash(git check-ignore:*)", + "Bash(git checkout:*)" ], "deny": [], "ask": [] diff --git a/package.json b/package.json index 9c1c1c6..b1c64c8 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,6 @@ "name": "zy-react-library", "private": false, "version": "1.1.20", - "type": "module", "description": "", "author": "LiuJiaNan", "license": "MIT", @@ -50,6 +49,7 @@ "@babel/preset-react": "^7.28.5", "@rollup/plugin-babel": "^6.1.0", "@rollup/plugin-commonjs": "^29.0.0", + "@rollup/plugin-image": "^3.0.3", "@rollup/plugin-json": "^6.1.0", "@rollup/plugin-node-resolve": "^16.0.3", "@rollup/plugin-terser": "^0.4.4", diff --git a/rollup.config.js b/rollup.config.js index 1163c4e..b3b299e 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -86,8 +86,9 @@ const babelConfig = { * 功能: * 1. 复制 .d.ts 类型声明文件 * 2. 复制 .less/.css 等样式文件(保持原始格式) - * 3. 复制 .json 数据文件(保持原始格式) - * 4. 复制 css 文件夹 + * 3. 复制图片文件 (.png, .jpg, .jpeg, .gif, .svg, .webp) + * 4. 复制 .json 数据文件(保持原始格式) + * 5. 复制 css 文件夹 * * 注意:所有源文件都在 src/ 目录,构建输出到根目录 */ @@ -140,10 +141,29 @@ const copyTypesPlugin = () => ({ source: content }); }); + + // ===== 3. 复制图片文件 (.png, .jpg, .jpeg, .gif, .svg, .webp) ===== + const imageFiles = glob.sync('**/*.{png,jpg,jpeg,gif,svg,webp}', { + cwd: dirPath, + absolute: true + }); + + imageFiles.forEach(file => { + const relativePath = path.relative(dirPath, file); + // 读取二进制文件,明确不使用编码 + const content = readFileSync(file, null); + + // 将图片文件添加到根目录,保持二进制格式 + this$1.emitFile({ + type: 'asset', + fileName: path.join(dir, relativePath), + source: content + }); + }); } }); - // ===== 3. 复制 json 文件夹(保持原始格式,不转换) ===== + // ===== 4. 复制 json 文件夹(保持原始格式,不转换) ===== const jsonDir = path.join(srcDir, 'json'); if (existsSync(jsonDir)) { const jsonFiles = glob.sync('**/*.json', { @@ -164,7 +184,7 @@ const copyTypesPlugin = () => ({ }); } - // ===== 4. 复制 css 文件夹 ===== + // ===== 5. 复制 css 文件夹 ===== const cssDir = path.join(srcDir, 'css'); if (existsSync(cssDir)) { const cssFiles = glob.sync('**/*', { @@ -195,7 +215,7 @@ const copyTypesPlugin = () => ({ * 2. babel - 转换 JSX * 3. commonjs - 转换 CommonJS 模块 * 4. json - 解析 JSON 导入(但被标记为 external,不会实际转换) - * 5. copyTypesPlugin - 复制类型和样式文件 + * 5. copyTypesPlugin - 复制类型、样式和图片文件 * 6. terser - 代码压缩 */ const plugins = [ @@ -261,7 +281,14 @@ const external = (id) => { return true; } - // 3. npm 依赖包标记为外部 -> 不打包到 bundle 中 + // 3. 图片文件标记为外部 -> 保留 import 语句,直接使用原始文件 + // 原因:图片文件会通过 copyTypesPlugin 复制到输出目录 + if (id.endsWith('.png') || id.endsWith('.jpg') || id.endsWith('.jpeg') || + id.endsWith('.gif') || id.endsWith('.svg') || id.endsWith('.webp')) { + return true; + } + + // 4. npm 依赖包标记为外部 -> 不打包到 bundle 中 // 原因:减少 bundle 体积,避免版本冲突,让消费者项目自己管理依赖 // 从 package.json 的 dependencies 中读取依赖列表 const dependencies = Object.keys(pkg.dependencies || {}); diff --git a/src/components/Map/CesiumMap.js b/src/components/Map/CesiumMap.js index ec7c5b2..f0002bd 100644 --- a/src/components/Map/CesiumMap.js +++ b/src/components/Map/CesiumMap.js @@ -1,4 +1,4 @@ -const billboardImage = require("./h.png"); +import billboardImage from './h.png'; export default class CesiumMap { viewer;