Skip to content

perf(s2-core): externalize lodash in UMD build to reduce bundle size#3267

Draft
Copilot wants to merge 51 commits intonextfrom
copilot/analyze-s2-core-package-size
Draft

perf(s2-core): externalize lodash in UMD build to reduce bundle size#3267
Copilot wants to merge 51 commits intonextfrom
copilot/analyze-s2-core-package-size

Conversation

Copy link
Contributor

Copilot AI commented Dec 25, 2025

s2-core UMD bundle was ~243KB brotli, exceeding the 240KB target. Root cause: full lodash library (~73KB minified) bundled due to 106 import { x } from 'lodash' imports.

Changes

  • rollup.config.mjs: Externalize lodash for UMD builds, map to global _
  • package.json: Update size-limit to ignore lodash (now external), lower target to 230kB

Results

Metric Before After
Brotli 243 KB 222 KB
Gzip 304 KB 280 KB

Breaking Change

UMD users must now include lodash separately:

<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.21/lodash.min.js"></script>
<script src="path/to/s2.min.js"></script>

ESM/CJS builds unchanged—lodash remains bundled inline.

Future Considerations

  • Migrate to lodash-es for ESM tree-shaking
  • Replace simple lodash utilities with native JS equivalents
Original prompt

我希望你执行pnpm i && pnpm run build,之后分析s2-core包的产物./dist/s2.min.js的size,检查是否有手段能够降低size。或者s2-core这个包是否违法了什么最佳实践,导致bao的size超出了240KB的限制。


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Alexzjt and others added 30 commits March 25, 2025 15:47
# Conflicts:
#	packages/s2-core/src/facet/base-facet.ts
…header

# Conflicts:
#	packages/s2-core/src/cell/header-cell.ts
# Conflicts:
#	packages/s2-core/package.json
#	packages/s2-core/src/sheet-type/spread-sheet.ts
#	pnpm-lock.yaml
…header

# Conflicts:
#	packages/s2-core/src/cell/DataCellPool.ts
#	packages/s2-core/src/cell/header-cell.ts
#	packages/s2-core/src/facet/base-facet.ts
Alexzjt and others added 20 commits September 4, 2025 19:50
…_0718

# Conflicts:
#	packages/s2-core/src/group/grid-group.ts
#	packages/s2-core/src/utils/g-renders.ts
#	packages/s2-react/playground/components/BigDataSheet.tsx
…header

# Conflicts:
#	packages/s2-core/src/cell/DataCellPool.ts
#	packages/s2-core/src/facet/base-facet.ts
#	packages/s2-core/src/utils/g-renders.ts
# Conflicts:
#	packages/s2-core/src/cell/col-cell.ts
#	packages/s2-core/src/cell/row-cell.ts
#	packages/s2-core/src/facet/header/base.ts
#	packages/s2-core/src/group/grid-group.ts
#	packages/s2-react/playground/components/BigDataSheet.tsx
Co-authored-by: Alexzjt <9548248+Alexzjt@users.noreply.github.com>
Copilot AI changed the title [WIP] Analyze s2-core package size and optimization methods perf(s2-core): externalize lodash in UMD build to reduce bundle size Dec 25, 2025
Copilot AI requested a review from Alexzjt December 25, 2025 03:38
Base automatically changed from perf/100w_header to next December 25, 2025 07:15
@github-actions github-actions bot added the next 2.0-next 版本的问题 label Dec 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

next 2.0-next 版本的问题

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments