Skip to content

Commit 9ef6664

Browse files
authored
docs(module): document module.parser.javascript.anonymousDefaultExportName (#8242)
Webpack 5.107 introduces a new JS parser option that controls whether webpack sets .name to "default" on anonymous default-export functions and classes (per the ES spec). The fix-up was added in 5.106 but the extra Object.defineProperty calls inflate bundles, so the option defaults to true for applications and false for libraries (when output.library is set). Documents the option under module.parser.javascript. Refs: webpack/webpack#20894
1 parent 64581a0 commit 9ef6664

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

src/content/configuration/module.mdx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,33 @@ export default {
710710

711711
It's allowed to configure those options in [`Rule.parser`](/configuration/module/#ruleparser) as well to target specific modules.
712712

713+
#### module.parser.javascript.anonymousDefaultExportName
714+
715+
<Badge text="5.107.0+" />
716+
717+
Controls whether webpack sets `.name` to `"default"` for anonymous default-export functions and classes, matching the ES spec for native ESM. When enabled, webpack injects a small runtime helper (`__webpack_require__.dn`) that calls `Object.defineProperty(...)` on the export to set the `.name` value.
718+
719+
- Type: `boolean`
720+
- Default: `true` for applications, `false` for libraries (when [`output.library`](/configuration/output/#outputlibrary) is set).
721+
722+
Applications stay spec-compliant by default. Libraries skip the helper to keep bundle size small, since library consumers rarely rely on `.name === "default"`.
723+
724+
To override the default explicitly:
725+
726+
**webpack.config.js**
727+
728+
```js
729+
export default {
730+
module: {
731+
parser: {
732+
javascript: {
733+
anonymousDefaultExportName: false,
734+
},
735+
},
736+
},
737+
};
738+
```
739+
713740
#### module.parser.javascript.commonjsMagicComments
714741

715742
Enable [magic comments](/api/module-methods/#magic-comments) support for CommonJS.

0 commit comments

Comments
 (0)