You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Do not import from the package root (`import { ChatbotToggle } from '@patternfly/chatbot'`).
33
+
Named imports from the root barrel also tree-shake with modern bundlers that respect the package `sideEffects` field.
34
+
35
+
`CodeModal`, `PreviewAttachment`, `AttachmentEdit`, and `tracking` are not exported from the root barrel — import them from `dist/dynamic/<Component>` instead. See `packages/module/patternfly-docs/content/extensions/chatbot/tree-shaking.md` for migration details.
Per-component `dist/dynamic` imports are preferred for faster builds and for components excluded from the root barrel (`CodeModal`, `PreviewAttachment`, `AttachmentEdit`).
42
+
35
43
## What to avoid
36
44
37
-
Do **not**import from the package root:
45
+
Do **not**use wildcard imports from the package root:
38
46
39
47
```tsx
40
-
// Avoid — pulls in the entire component barrel
41
-
import{ ChatbotToggle }from'@patternfly/chatbot';
48
+
// Avoid — may pull in the entire library
49
+
import*asChatbotfrom'@patternfly/chatbot';
42
50
```
43
51
44
-
The root `index.js` re-exports every ChatBot component. Bundlers cannot eliminate unused exports from this autogenerated barrel, so your bundle will include components you never render.
45
-
46
52
## Icon imports
47
53
48
-
ChatBot source code imports icons individually from deep paths so they tree-shake correctly:
54
+
Which PatternFly icons end up in your bundle depends on **which ChatBot components you import**, not on whether those components use deep or barrel icon paths internally. Importing `ChatbotToggle` from its subpath includes only the icons that component uses — currently four icons in the tree-shaking demo.
55
+
56
+
ChatBot source code uses deep-path icon imports as a defensive convention:
In your own application code, follow the same pattern. Avoid importing from the `@patternfly/react-icons` barrel:
62
+
Deep paths improve **build performance** (less barrel resolution) and work reliably across bundler configurations. They do not meaningfully change **runtime bundle size** compared to named barrel imports when using modern bundlers, because `@patternfly/react-icons` declares `sideEffects: false`.
63
+
64
+
In your own application code, deep paths are still recommended:
`CodeModal`, `PreviewAttachment`, and `AttachmentEdit` are excluded from the root barrel so Monaco stays out of bundles that do not use attachment editing. Import them from dynamic entry points:
98
+
`CodeModal`, `PreviewAttachment`, and `AttachmentEdit` are excluded from the root barrel so Monaco stays out of root-barrel bundles. Import them from dynamic entry points:
@@ -95,9 +104,28 @@ import AttachmentEdit from '@patternfly/chatbot/dist/dynamic/AttachmentEdit';
95
104
96
105
`monaco-editor` and `@monaco-editor/react` are peer dependencies when you use these components.
97
106
107
+
## Migration: root barrel changes
108
+
109
+
The following modules are **not** re-exported from the root barrel (`@patternfly/chatbot`). They were removed so Monaco and internal utilities stay out of default bundles. Update existing root imports to subpath entry points:
110
+
111
+
| Module | Before (no longer works) | After |
112
+
|--------|--------------------------|-------|
113
+
|`CodeModal`|`import { CodeModal } from '@patternfly/chatbot'`|`import CodeModal from '@patternfly/chatbot/dist/dynamic/CodeModal'`|
114
+
|`PreviewAttachment`|`import { PreviewAttachment } from '@patternfly/chatbot'`|`import PreviewAttachment from '@patternfly/chatbot/dist/dynamic/PreviewAttachment'`|
115
+
|`AttachmentEdit`|`import { AttachmentEdit } from '@patternfly/chatbot'`|`import AttachmentEdit from '@patternfly/chatbot/dist/dynamic/AttachmentEdit'`|
116
+
|`tracking`|`import { getTrackingProviders } from '@patternfly/chatbot'`|`import { getTrackingProviders } from '@patternfly/chatbot/dist/dynamic/tracking'`|
117
+
118
+
All other components remain available from the root barrel and continue to tree-shake when your bundler respects the package `sideEffects` field.
119
+
120
+
When using `CodeModal`, `PreviewAttachment`, or `AttachmentEdit`, also import the Monaco worker helper once at application startup:
121
+
122
+
```tsx
123
+
import'@patternfly/chatbot/monaco-environment';
124
+
```
125
+
98
126
## Verify tree-shaking in your project
99
127
100
-
The repository includes a tree-shaking demo at `packages/tree-shaking-demo/` that builds three scenarios and compares bundle size, icon count, and component count:
128
+
The repository includes a tree-shaking demo at `packages/tree-shaking-demo/` that builds four scenarios and compares bundle size, icon count, and component count:
101
129
102
130
```bash
103
131
npm run build -w @patternfly/chatbot
@@ -106,9 +134,22 @@ npm run analyze:tree-shaking
106
134
107
135
Open the generated `dist/<scenario>/stats.html` files for interactive bundle visualizations.
The **published** scenario resolves `@patternfly/chatbot` through `package.json``exports` and `dist/` with no monorepo source alias, matching how npm consumers resolve the package.
147
+
109
148
## How ChatBot supports tree-shaking
110
149
111
150
-**ESM output** with a `module` field pointing to `dist/esm/`
112
-
-**Per-component entry points** at `dist/dynamic/<Component>/`
113
-
-**Deep icon imports** in library source code
114
-
-**`exports`** field maps public subpaths (`dist/dynamic/*`, `dist/css/main.css`, `monaco-environment`) for bundler-friendly resolution
151
+
-**`sideEffects`** in `package.json` so bundlers can drop unused re-exports from the root barrel while preserving CSS and the documentation-site style entry (`patternfly-docs/**`)
152
+
-**Per-component dynamic entry points** at `dist/dynamic/<Component>/`
153
+
-**Unbundled compilation** — icons and dependencies remain as external imports for your bundler to resolve
154
+
-**`exports`** field maps public subpaths for bundler-friendly resolution
0 commit comments