master
parent
a46e7b1f72
commit
842b5ec25a
|
|
@ -7,7 +7,8 @@
|
|||
"Bash(tree:*)",
|
||||
"Bash(cat:*)",
|
||||
"Bash(git rm:*)",
|
||||
"Bash(git check-ignore:*)"
|
||||
"Bash(git check-ignore:*)",
|
||||
"Bash(git checkout:*)"
|
||||
],
|
||||
"deny": [],
|
||||
"ask": []
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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 || {});
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
const billboardImage = require("./h.png");
|
||||
import billboardImage from './h.png';
|
||||
|
||||
export default class CesiumMap {
|
||||
viewer;
|
||||
|
|
|
|||
Loading…
Reference in New Issue