Skip to content

引入

ts
import {
  IZipSizeResult,
  IGetZipSizeOptions,
  analyzeIndexBundle,
  getZipSize
} from 't-comm';

// 不支持 tree-shaking 的项目
import {
  IZipSizeResult,
  IGetZipSizeOptions,
  analyzeIndexBundle,
  getZipSize
} from 't-comm/lib/bundle-analyze/index';

// 只支持 ESM 的项目
import {
  IZipSizeResult,
  IGetZipSizeOptions,
  analyzeIndexBundle,
  getZipSize
} from 't-comm/es/bundle-analyze/index';

IZipSizeResult

描述getZipSize 的返回结果

参数

iZipSizeResult.zipSize : number | null

zip 压缩后字节数。无法估算时为 null

Kind: instance property of IZipSizeResult

iZipSizeResult.zipMethod : 'zip' | 'gzip-sum' | 'none'

体积来源:

  • zip : 系统 zip 命令打成真实 zip 包,最准
  • gzip-sum: zlib.gzipSync 逐文件累加,估算值,比真实 zip 略大(无共享字典)
  • none : 两种方式都失败

Kind: instance property of IZipSizeResult

IGetZipSizeOptions

描述getZipSize 入参

参数

iGetZipSizeOptions.outputDir : string

产物目录绝对路径(必填)

Kind: instance property of IGetZipSizeOptions

iGetZipSizeOptions.files : Array<object>

已采集到的产物文件相对路径列表(来自 outputDir 的相对路径)。 仅在 gzip-sum 降级分支使用;不传时降级分支会自行递归 outputDir

Kind: instance property of IGetZipSizeOptions
Optional:
Properties

NameType
namestring

iGetZipSizeOptions.excludeGlobs : Array

zip 模式下要排除的 glob 模式,默认 ['*.map'](sourcemap)

Kind: instance property of IGetZipSizeOptions
Optional:

iGetZipSizeOptions.excludeMapInGzip : boolean

gzip 兜底分支是否同样跳过 sourcemap,默认 true

Kind: instance property of IGetZipSizeOptions
Optional:

iGetZipSizeOptions.zipBin : string

zip 命令所在路径,默认 'zip'(依赖 PATH)

Kind: instance property of IGetZipSizeOptions
Optional:

analyzeIndexBundle(config)

描述:分析首页Bundle信息

参数

参数名类型描述
config配置
config.domainstring域名
config.buildPathstring打包路径

示例

ts
analyzeIndexBundle({
  domain: '',
  buildPath: '',
})

getZipSize()

描述:获取构建产物目录的 zip 压缩后体积,跨平台兜底。 估算策略:

    - 优先调用系统 `zip` 命令打成真实 zip 包,删除后返回字节数(最准) - 不可用时,降级为 `zlib.gzipSync` 逐文件累加(估算值,比真实 zip 略大,因为没有共享字典) - 仍失败则返回 `{ zipSize: null, zipMethod: 'none' }`
Windows 默认没有 `zip` 命令,会自动降级到 gzip-sum,无需额外配置。

参数

示例

ts
import { getZipSize } from 't-comm';

const { zipSize, zipMethod } = getZipSize({ outputDir: '/path/to/dist' });
console.log(zipSize, zipMethod); // 1234567 'zip'