Skip to content

Commit e32a384

Browse files
authored
docs: update output.devtoolNamespace (#7425)
1 parent 66d98fc commit e32a384

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/content/configuration/output.mdx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,23 @@ If multiple modules would result in the same name, [`output.devtoolFallbackModul
420420

421421
This option determines the module's namespace used with the [`output.devtoolModuleFilenameTemplate`](#outputdevtoolmodulefilenametemplate). When not specified, it will default to the value of: [`output.uniqueName`](#outputuniquename). It's used to prevent source file path collisions in sourcemaps when loading multiple libraries built with webpack.
422422

423-
For example, if you have 2 libraries, with namespaces `library1` and `library2`, which both have a file `./src/index.js` (with potentially different contents), they will expose these files as `webpack://library1/./src/index.js` and `webpack://library2/./src/index.js`.
423+
For example, if you have 2 libraries, with namespaces `library1` and `library2`, which both have a file `./src/index.js` (with potentially different contents), they will expose these files as `webpack://library1/./src/index.js` and `webpack://library2/./src/index.js`.
424+
425+
You can use template strings like `[name]` to dynamically generate namespaces based on the build context, providing additional flexibility.
426+
427+
**webpack.config.js**
428+
429+
```javascript
430+
module.exports = {
431+
//...
432+
output: {
433+
filename: "[name]-bundle.js",
434+
library: "library-[name]",
435+
libraryTarget: "commonjs",
436+
devtoolNamespace: "library-[name]" // Sets a unique namespace for each library
437+
},
438+
};
439+
```
424440

425441
## output.enabledChunkLoadingTypes
426442

0 commit comments

Comments
 (0)