Skip to content

Commit c5cfbed

Browse files
authored
add info about dynamic imports to nextjs docs (#1564)
* add info about dynamic imports to nextjs docs * remove warning
1 parent 1e4fd13 commit c5cfbed

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

docs/guide/packages/lucide-react.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,6 @@ export default App;
9999

100100
#### With Dynamic Imports
101101

102-
> :warning: This is experimental and only works with bundlers that support dynamic imports.
103-
104102
Lucide react exports a dynamic import map `dynamicIconImports`, which is useful for applications that want to show icons dynamically by icon name. For example, when using a content management system with where icon names are stored in a database.
105103

106104
When using client side rendering, it will fetch the icon component when it's needed. This will reduce the initial bundle size.
@@ -134,7 +132,21 @@ export default Icon
134132

135133
##### NextJS Example
136134

137-
In NextJS [the dynamic function](https://nextjs.org/docs/pages/building-your-application/optimizing/lazy-loading#nextdynamic) can be used to load the icon component dynamically.
135+
In NextJS, [the dynamic function](https://nextjs.org/docs/pages/building-your-application/optimizing/lazy-loading#nextdynamic) can be used to dynamically load the icon component.
136+
137+
To make dynamic imports work with NextJS, you need to add `lucide-react` to the [`transpilePackages`](https://nextjs.org/docs/app/api-reference/next-config-js/transpilePackages) option in your `next.config.js` like this:
138+
139+
```js
140+
/** @type {import('next').NextConfig} */
141+
const nextConfig = {
142+
transpilePackages: ['lucide-react'] // add this
143+
}
144+
145+
module.exports = nextConfig
146+
147+
```
148+
149+
You can then start using it:
138150

139151
```tsx
140152
import dynamic from 'next/dynamic'

packages/lucide-react/README.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,6 @@ export default Icon;
7373

7474
#### With Dynamic Imports
7575

76-
> :warning: This is experimental and only works with bundlers that support dynamic imports.
77-
7876
Lucide react exports a dynamic import map `dynamicIconImports`. Useful for applications that want to show icons dynamically by icon name. For example when using a content management system with where icon names are stored in a database.
7977

8078
When using client side rendering, it will fetch the icon component when it's needed. This will reduce the initial bundle size.
@@ -108,7 +106,21 @@ export default Icon
108106

109107
##### NextJS Example
110108

111-
In NextJS [the dynamic function](https://nextjs.org/docs/pages/building-your-application/optimizing/lazy-loading#nextdynamic) can be used to load the icon component dynamically.
109+
In NextJS, [the dynamic function](https://nextjs.org/docs/pages/building-your-application/optimizing/lazy-loading#nextdynamic) can be used to dynamically load the icon component.
110+
111+
To make dynamic imports work with NextJS, you need to add `lucide-react` to the [`transpilePackages`](https://nextjs.org/docs/app/api-reference/next-config-js/transpilePackages) option in your `next.config.js` like this:
112+
113+
```js
114+
/** @type {import('next').NextConfig} */
115+
const nextConfig = {
116+
transpilePackages: ['lucide-react'] // add this
117+
}
118+
119+
module.exports = nextConfig
120+
121+
```
122+
123+
You can then start using it:
112124

113125
```tsx
114126
import dynamic from 'next/dynamic'

0 commit comments

Comments
 (0)