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`).
41
+
35
42
## What to avoid
36
43
37
-
Do **not**import from the package root:
44
+
Do **not**use wildcard imports from the package root:
38
45
39
46
```tsx
40
-
// Avoid — pulls in the entire component barrel
41
-
import{ ChatbotToggle }from'@patternfly/chatbot';
47
+
// Avoid — may pull in the entire library
48
+
import*asChatbotfrom'@patternfly/chatbot';
42
49
```
43
50
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
51
## Icon imports
47
52
48
-
ChatBot source code imports icons individually from deep paths so they tree-shake correctly:
Which PatternFly icons end up in your bundle depends on **which ChatBot components you import**, not on whether ChatBot source code or your app uses barrel or deep icon paths. Importing `ChatbotToggle` via `dist/dynamic` includes only the icons that component uses — currently four icons in the tree-shaking demo.
`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:
74
+
`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 +80,28 @@ import AttachmentEdit from '@patternfly/chatbot/dist/dynamic/AttachmentEdit';
95
80
96
81
`monaco-editor` and `@monaco-editor/react` are peer dependencies when you use these components.
97
82
83
+
## Migration: root barrel changes
84
+
85
+
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:
86
+
87
+
| Module | Before (no longer works) | After |
88
+
|--------|--------------------------|-------|
89
+
|`CodeModal`|`import { CodeModal } from '@patternfly/chatbot'`|`import CodeModal from '@patternfly/chatbot/dist/dynamic/CodeModal'`|
90
+
|`PreviewAttachment`|`import { PreviewAttachment } from '@patternfly/chatbot'`|`import PreviewAttachment from '@patternfly/chatbot/dist/dynamic/PreviewAttachment'`|
91
+
|`AttachmentEdit`|`import { AttachmentEdit } from '@patternfly/chatbot'`|`import AttachmentEdit from '@patternfly/chatbot/dist/dynamic/AttachmentEdit'`|
92
+
|`tracking`|`import { getTrackingProviders } from '@patternfly/chatbot'`|`import { getTrackingProviders } from '@patternfly/chatbot/dist/dynamic/tracking'`|
93
+
94
+
All other components remain available from the root barrel and continue to tree-shake when your bundler respects the package `sideEffects` field.
95
+
96
+
When using `CodeModal`, `PreviewAttachment`, or `AttachmentEdit`, also import the Monaco worker helper once at application startup:
97
+
98
+
```tsx
99
+
import'@patternfly/chatbot/monaco-environment';
100
+
```
101
+
98
102
## Verify tree-shaking in your project
99
103
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:
104
+
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
105
102
106
```bash
103
107
npm run build -w @patternfly/chatbot
@@ -106,9 +110,22 @@ npm run analyze:tree-shaking
106
110
107
111
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.
123
+
109
124
## How ChatBot supports tree-shaking
110
125
111
126
-**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
127
+
-**`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/**`)
128
+
-**Per-component dynamic entry points** at `dist/dynamic/<Component>/`
129
+
-**Unbundled compilation** — icons and dependencies remain as external imports for your bundler to resolve
130
+
-**`exports`** field maps public subpaths for bundler-friendly resolution
0 commit comments