|
3 | 3 | **webpack-react-component-name** is a Webpack plugin that makes your custom |
4 | 4 | React components visible within React Dev Tools and other tools that rely on the displayName parameter. |
5 | 5 |
|
6 | | -*Note: This fork contains the version of this plugin that is compatible with |
7 | | -Webpack 5. For support for Webpack 4, see version 4.x of the [Original Repo](https://github.com/runreflect/webpack-react-component-name/releases/tag/4.0.5).* |
| 6 | +_Note: This fork contains the version of this plugin that is compatible with |
| 7 | +Webpack 5. For support for Webpack 4, see version 4.x of the [Original Repo](https://github.com/runreflect/webpack-react-component-name/releases/tag/4.0.5)._ |
8 | 8 |
|
9 | | -Normally React component names are minified during compilation. This plugin |
| 9 | +Normally React component names are minified during compilation. This plugin |
10 | 10 | makes these component names available in production bundles by hooking into |
11 | 11 | Webpack's compilation process, traversing the AST looking for React component |
12 | | -definitions, and updating the emitted source code to populate the |
| 12 | +definitions, and updating the emitted source code to populate the |
13 | 13 | [displayName](https://reactjs.org/docs/react-component.html#displayname) |
14 | | -property. This is the property that, when populated, is used by the React Dev |
| 14 | +property. This is the property that, when populated, is used by the React Dev |
15 | 15 | Tools extension to determine the name of a component. |
16 | 16 |
|
17 | 17 | Since we emit a `displayName` property value for each React component definition |
18 | | -(critically, **not** every React component *instance*), using this plugin will |
| 18 | +(critically, **not** every React component _instance_), using this plugin will |
19 | 19 | result in a small size increase to your production bundles. |
20 | 20 |
|
21 | 21 | ## Installation |
@@ -51,33 +51,55 @@ Default: `false` |
51 | 51 |
|
52 | 52 | If set true, the plugin will name the components exported from node_modules. |
53 | 53 |
|
| 54 | +### include |
54 | 55 |
|
55 | | -### include |
56 | 56 | Type: `(string | RegExp | (path: string) => boolean)[]` Default: `[]` |
57 | 57 |
|
58 | 58 | If the path matches any of the elements in this array, it will be included if it isn't explicitly excluded. |
59 | 59 |
|
60 | | -If the item is a `string`, it will use standard glob syntax. If the item is a Regular Expression, the path will be tested against it. If the item is a function, the path will be passed into it for testing. |
| 60 | +If the item is a `string`, it will use standard glob syntax. If the item is a Regular Expression, the path will be tested against it. If the item is a function, the path will be passed into it for testing. |
| 61 | + |
| 62 | +### exclude |
61 | 63 |
|
62 | | -### exclude |
63 | 64 | Type: `(string | RegExp | (path: string) => boolean)[]` Default: `[]` |
64 | 65 |
|
65 | 66 | If the path matches any of the elements in this array, it will be excluded. |
66 | 67 |
|
67 | | -If the item is a `string`, it will use standard glob syntax. If the item is a Regular Expression, the path will be tested against it. If the item is a function, the path will be passed into it for testing. |
| 68 | +If the item is a `string`, it will use standard glob syntax. If the item is a Regular Expression, the path will be tested against it. If the item is a function, the path will be passed into it for testing. |
| 69 | + |
| 70 | +A truthy result will be excluded. |
68 | 71 |
|
69 | | -A truthy result will be excluded. |
70 | 72 | ## Troubleshooting |
71 | 73 |
|
72 | | -As you probably know, there is more than one way to define a React component. This |
| 74 | +As you probably know, there is more than one way to define a React component. This |
73 | 75 | plugin attempts to detect every possible way of defining a component, but there may |
74 | | -be some we've missed. See the `/examples` directory and the unit tests for examples |
| 76 | +be some we've missed. See the `/examples` directory and the unit tests for examples |
75 | 77 | of the different permutations of React component definitions that we currently support. |
76 | 78 |
|
77 | 79 | If we are not detecting one of your components, please either file an Issue containing |
78 | 80 | example source for a component which is not detected, or feel free to open a PR with |
79 | 81 | the fix. |
80 | 82 |
|
| 83 | +## Note for Next.js users |
| 84 | + |
| 85 | +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. |
| 86 | + |
| 87 | +```js |
| 88 | +const webpackComponentNamesAppenderCacheWarning = |
| 89 | + /Skipped not serializable cache item.*ModuleAppenderDependency/i; |
| 90 | + |
| 91 | +config.infrastructureLogging = { |
| 92 | + stream: { |
| 93 | + write: (message) => { |
| 94 | + if (webpackComponentNamesAppenderCacheWarning.test(message)) { |
| 95 | + return; |
| 96 | + } |
| 97 | + process.stderr.write(message); |
| 98 | + }, |
| 99 | + }, |
| 100 | +}; |
| 101 | +``` |
| 102 | + |
81 | 103 | ## License |
82 | 104 |
|
83 | 105 | This project is licensed under the terms of the MIT license. See `LICENSE.md` for more info. |
0 commit comments