Skip to content

Commit a3c0031

Browse files
committed
docs: explain scoped imports from entry points
Signed-off-by: Jan Kowalleck <jan.kowalleck@gmail.com>
1 parent ea8aa34 commit a3c0031

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ See extended [examples].
141141

142142
### As _Node.js_ package
143143

144+
Import all at once and use it:
145+
144146
```javascript
145147
const CDX = require('@cyclonedx/cyclonedx-library')
146148

@@ -157,6 +159,25 @@ bom.components.add(componentA)
157159
bom.metadata.component.dependencies.add(componentA.bomRef)
158160
```
159161

162+
To support _bundling_ and _tree-shaking_ in your project, it is recommended to only import the symbols from the [entry points](https://nodejs.org/api/packages.html#package-entry-points) that are actually needed. (For a list of available entry points, see `package.json::exports`.)
163+
164+
```javascript
165+
const { Bom, Component } = require('@cyclonedx/cyclonedx-library/Models')
166+
const { ComponentType } = require('@cyclonedx/cyclonedx-library/Enums')
167+
168+
const bom = new Bom()
169+
bom.metadata.component = new Component(
170+
ComponentType.Application,
171+
'MyProject'
172+
)
173+
const componentA = new Component(
174+
ComponentType.Library,
175+
'myComponentA',
176+
)
177+
bom.components.add(componentA)
178+
bom.metadata.component.dependencies.add(componentA.bomRef)
179+
```
180+
160181
### In _WebBrowsers_
161182

162183
```html

0 commit comments

Comments
 (0)