Skip to content

Conversation

@punkbit
Copy link
Collaborator

@punkbit punkbit commented Jan 26, 2026

Why?

The following PR makes the distributed files "unbundled", effectively moving optimisation to a consumer app concern, e.g. obfuscation, compression, bundling MUST be consumer concerns, the library SHOULD NOT make the consumer bundling process more difficult, it MUST facilitate it! It resolves cyclic imports or circular dependencies, enhances linting to prevent imports from barrel files, making the barrel files more of a public API than an internal API to help prevent circular dependencies.

From now on, bundling preserves the file tree, externalises packages based on the package.json dependency declaration automatically, instead of managing them manually as the current version does. It allows deep imports, e.g. @clickhouse/click-ui/components/Button.

Exports files are placed by target resolution, e.g. dist/esm|cjs. It has removed UMD until further notice (why is the original version providing UMD, what's the use-case?). As a component library, in principle, it should be ESM and CJS (due to NodeJS SSR) compatible in the worse case scenarios.

It reduces build times from > 1 minute to < 22 seconds.

More importantly, this initial revision provides tree-shaking support, helping reduce file size. Which can now be assessed with an optional builder feature to analyse and visualise the package dependency graph, file sizes, etc.

⚠️ WARNING: Depends on #756, which should be integrated/merged first!

How?

  • Resolve circular dependencies
  • Add lint rule to help prevent declaring imports from barrel file
  • Exports file and types re-architecture
  • Distributes unbundled package moving optimization to consumer
  • Add support for deep imports (although there's use of Theme provider/wrapper at the moment which some components consume, but will be deprecated)
  • Add support tree shaking
  • Add a builder/package analyzer and visualizer to assess package in a dependency graphy ands sizes
  • Update documentation
  • Removes UMD (until further evidence of required support)

Preview?

Circular dependencies

cui-circular-dependencies

Analysis for the current production version

demo-analytics-visualizer-es.mov
demo-analyzer-visualizer-stats-standard-umd.mov
demo-bundle-analyze-visualize-current-main-is-bad.mov

Analysis for proposed PR version

demo-proposed-pr-pkg-analysis.mov

Docusaurus on current production version

💁‍♀️ Showing docusaurs since the reason why "bundled" version was introduced was due to "click-ui failure to work in docusaurus"

demo-docusaurus-with-es-bundled

Docusaurus on PR proposed version

demo-docusaurus-with-es-unbundled-network-size

Distribution file size (before)

dist-file-size-before
dist
├── App.d.ts
├── click-ui.bundled.es.js
├── click-ui.bundled.es.js.map
├── click-ui.bundled.umd.js
├── click-ui.bundled.umd.js.map
├── click-ui.es.js
├── click-ui.es.js.map
├── click-ui.umd.js
├── click-ui.umd.js.map
├── clickhouse-backs.png
├── components
│   ├── Accordion
│   ├── Alert
│   ├── AutoComplete
│   ├── Avatar
│   ├── Badge
│   ├── BigStat
│   ├── Button
│   ├── ButtonGroup
│   ├── CardHorizontal
│   ├── CardPrimary
│   ├── CardPromotion
│   ├── CardSecondary
│   ├── Checkbox
│   ├── CodeBlock
│   ├── Collapsible
│   ├── ConfirmationDialog
│   ├── Container
│   ├── ContextMenu
│   ├── DateDetails
│   ├── DatePicker
│   ├── Dialog
│   ├── Dropdown
│   ├── EllipsisContent
│   ├── FileTabs
│   ├── FileUpload
│   ├── Flyout
│   ├── FormContainer
│   ├── GenericLabel
│   ├── GenericMenu.d.ts
│   ├── Grid
│   ├── GridContainer
│   ├── HoverCard
│   ├── Icon
│   ├── IconButton
│   ├── IconWrapper
│   ├── Input
│   ├── Label
│   ├── Link
│   ├── Logos
│   ├── MultiAccordion
│   ├── Pagination
│   ├── Panel
│   ├── Popover
│   ├── ProgressBar
│   ├── RadioGroup
│   ├── Select
│   ├── Separator
│   ├── SidebarCollapsibleItem
│   ├── SidebarCollapsibleTitle
│   ├── SidebarNavigationItem
│   ├── SidebarNavigationTitle
│   ├── Spacer
│   ├── SplitButton
│   ├── Switch
│   ├── Table
│   ├── Tabs
│   ├── Toast
│   ├── Tooltip
│   ├── Typography
│   ├── VerticalStepper
│   ├── commonElement.d.ts
│   ├── commonTypes.d.ts
│   ├── cursorOptions.d.ts
│   ├── icons
│   ├── index.d.ts
│   └── types.d.ts
├── examples
│   └── GridExample.d.ts
├── favicon.ico
├── hooks
│   ├── index.d.ts
│   └── useUpdateEffect.d.ts
├── index.d.ts
├── lib
│   ├── EventEmitter.d.ts
│   └── getTextFromNodes.d.ts
├── logo.svg
├── main.d.ts
├── theme
│   ├── ClickUIProvider
│   ├── index.d.ts
│   ├── theme.d.ts
│   └── tokens
└── utils
    ├── date.d.ts
    ├── mergeRefs.d.ts
    ├── test-utils.d.ts
    └── truncate.d.ts

69 directories, 31 files

Distribution file size (after)

Screenshot 2026-01-26 at 11 22 04
dist
├── cjs
│   ├── components
│   ├── hooks
│   ├── index.cjs
│   ├── index.cjs.map
│   ├── lib
│   ├── theme
│   └── utils
├── esm
│   ├── components
│   ├── hooks
│   ├── index.js
│   ├── index.js.map
│   ├── lib
│   ├── theme
│   └── utils
└── types
    ├── components
    ├── hooks
    ├── index.d.ts
    ├── lib
    ├── theme
    └── utils

19 directories, 5 files

Build times

On a macOS ventura m2 max pro:

Current production version >= 1 minute

yarn build  61.73s user 5.33s system 160% cpu 41.792 total

PR proposed version <= 22s

yarn build  21.90s user 2.00s system 163% cpu 14.592 total

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants