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
Copy file name to clipboardExpand all lines: README.md
+90-23Lines changed: 90 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@
4
4
5
5
# React displayName Plugin
6
6
7
-
**react-display-name-plugin** is a build plugin for both Webpack and Vite that makes your custom
7
+
**react-display-name-plugin** is a build plugin for Webpack, Next.js & Vite that makes your custom
8
8
React components visible within React Dev Tools and other tools that rely on the displayName parameter.
9
9
10
10
_Note: This package supports Webpack 5 and Vite 2+. For older versions (Webpack 4), see the legacy package [@mockingjay-io/webpack-react-component-name](https://github.com/mockingjay-io/webpack-react-component-name)._
@@ -46,8 +46,6 @@ module.exports = {
46
46
};
47
47
```
48
48
49
-
**Next.js users** have to add this within `next.config.js`/`next.config.mjs`/`next.config.ts`. Examples available [here](https://github.com/mockingjay-io/react-display-name-plugin/tree/main/examples).
50
-
51
49
### For Vite
52
50
53
51
2. Import and add the plugin to your Vite configuration:
@@ -70,6 +68,95 @@ export default defineConfig({
70
68
71
69
**Note:** The Vite plugin should be placed after the React plugin in your plugins array, as it needs to run after JSX transformation.
72
70
71
+
### For Next.js
72
+
73
+
Next.js uses Webpack under the hood, so you'll need to customize the Webpack configuration in your Next.js config file.
74
+
75
+
> **⚠️ Important:** This plugin currently only works with Webpack. If you're using Turbopack (Next.js's new bundler), you'll need to [opt back into using Webpack](https://nextjs.org/docs/app/api-reference/turbopack#using-webpack-instead) by removing the `--turbo` flag from your dev command or setting `experimental.turbo` to `false` in your config.
Next.js may generate warnings like `[webpack.cache.PackFileCacheStrategy] Skipped not serializable cache item`. These are safe to ignore, but if you want to suppress them:
/Skipped not serializable cache item.*ModuleAppenderDependency/i;
128
+
129
+
/**@type{import('next').NextConfig}*/
130
+
constnextConfig= {
131
+
webpack: (config) => {
132
+
config.plugins.push(
133
+
newReactDisplayNamePlugin({
134
+
parseDependencies:true,
135
+
})
136
+
);
137
+
138
+
// Suppress cache warnings
139
+
config.infrastructureLogging= {
140
+
level:'error',
141
+
stream: {
142
+
write: (message) => {
143
+
if (webpackComponentNamesAppenderCacheWarning.test(message)) {
144
+
return;
145
+
}
146
+
process.stderr.write(message);
147
+
},
148
+
},
149
+
};
150
+
151
+
return config;
152
+
},
153
+
};
154
+
155
+
exportdefaultnextConfig;
156
+
```
157
+
158
+
**See working examples:** Check the [examples directory](https://github.com/mockingjay-io/react-display-name-plugin/tree/main/examples) for Next.js 12, 13, and 14 configurations with both App Router and Pages Router.
159
+
73
160
### Core Utilities (Advanced)
74
161
75
162
For building custom plugins for other bundlers, you can import the core utilities directly:
@@ -144,26 +231,6 @@ If we are not detecting one of your components, please either file an Issue cont
144
231
example source for a component which is not detected, or feel free to open a PR with
145
232
the fix.
146
233
147
-
## Note for Next.js users
148
-
149
-
In Next.js the plugin may cause warnings like `[webpack.cache.PackFileCacheStrategy] Skipped not serializable cache item` to be generated. These warnings are safe to ignore without any further action. But if you'd like to supress these warnings, as an interim solution, the following snippet can be added to your webpack config.
150
-
151
-
```js
152
-
constwebpackComponentNamesAppenderCacheWarning=
153
-
/Skipped not serializable cache item.*ModuleAppenderDependency/i;
154
-
155
-
config.infrastructureLogging= {
156
-
stream: {
157
-
write: (message) => {
158
-
if (webpackComponentNamesAppenderCacheWarning.test(message)) {
159
-
return;
160
-
}
161
-
process.stderr.write(message);
162
-
},
163
-
},
164
-
};
165
-
```
166
-
167
234
## License
168
235
169
236
This project is licensed under the terms of the MIT license. See `LICENSE.md` for more info.
0 commit comments