Skip to content

Commit b1c8118

Browse files
committed
Add tree-shaking demo
i modified: packages/module/patternfly-docs/content/extensions/chatbot/examples/Messages/BotMessage.tsx
1 parent 6dbaaf2 commit b1c8118

41 files changed

Lines changed: 3988 additions & 1949 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,27 @@ import '@patternfly/chatbot/dist/css/main.css';
2222

2323
If you are using React 17, ChatBot currently has a dependency on [react-markdown](https://github.com/remarkjs/react-markdown) that relies on React 18 and 19. There is an older version of react-markdown (8.0.7) that supports 17, but it does not have support for 19. You should be able to add `"react"` and `"react-dom"` of the appropriate version to the `overrides` section of your `package.json` file if you need to use ChatBot with 17.
2424

25+
### Tree-shaking
26+
27+
Import each component from its dynamic entry point to keep bundle size minimal:
28+
29+
```tsx
30+
import ChatbotToggle from '@patternfly/chatbot/dist/dynamic/ChatbotToggle';
31+
```
32+
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.
36+
37+
To verify tree-shaking in this repo:
38+
39+
```bash
40+
npm run build -w @patternfly/chatbot
41+
npm run analyze:tree-shaking
42+
```
43+
44+
See `packages/tree-shaking-demo/README.md` for full results and best practices.
45+
2546
## Contribution guide
2647

2748
### AI-assisted development guidelines

config/setupTests.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
import 'whatwg-fetch';
33
import 'babel-polyfill';
44
import '@testing-library/jest-dom';
5+
beforeAll(async () => {
6+
await import('../packages/module/src/MarkdownContent/MarkdownRenderer');
7+
});
58

69
global.SVGPathElement = function () {};
710

jest.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ module.exports = {
3030
modulePathIgnorePatterns: [
3131
'<rootDir>/packages/*.*/dist/*.*',
3232
'<rootDir>/packages/*.*/public/*.*',
33-
'<rootDir>/packages/*.*/.cache/*.*'
33+
'<rootDir>/packages/*.*/.cache/*.*',
34+
'<rootDir>/packages/tree-shaking-demo/*.*'
3435
],
3536
moduleNameMapper: {
3637
'\\.(css|scss)$': 'identity-obj-proxy',

0 commit comments

Comments
 (0)