Skip to content

Commit 6816201

Browse files
authored
docs: sort resolve options (#7201)
1 parent 6e18b81 commit 6816201

File tree

1 file changed

+116
-116
lines changed

1 file changed

+116
-116
lines changed

src/content/configuration/resolve.mdx

Lines changed: 116 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,53 @@ module.exports = {
170170
};
171171
```
172172

173+
### resolve.byDependency
174+
175+
Configure resolve options by the type of module request.
176+
177+
- Type: `[type: string]: ResolveOptions`
178+
- Example:
179+
180+
```js
181+
module.exports = {
182+
// ...
183+
resolve: {
184+
byDependency: {
185+
// ...
186+
esm: {
187+
mainFields: ['browser', 'module'],
188+
},
189+
commonjs: {
190+
aliasFields: ['browser'],
191+
},
192+
url: {
193+
preferRelative: true,
194+
},
195+
},
196+
},
197+
};
198+
```
199+
200+
### resolve.cachePredicate
201+
202+
`function(module) => boolean`
203+
204+
A function which decides whether a request should be cached or not. An object is passed to the function with `path` and `request` properties. It must return a boolean.
205+
206+
**webpack.config.js**
207+
208+
```js
209+
module.exports = {
210+
//...
211+
resolve: {
212+
cachePredicate: (module) => {
213+
// additional logic
214+
return true;
215+
},
216+
},
217+
};
218+
```
219+
173220
### resolve.cacheWithContext
174221

175222
`boolean`
@@ -273,6 +320,23 @@ module.exports = {
273320
};
274321
```
275322

323+
### resolve.exportsFields
324+
325+
`[string] = ['exports']`
326+
327+
Fields in package.json that are used for resolving module requests. See [package-exports guideline](/guides/package-exports/) for more information.
328+
329+
**webpack.config.js**
330+
331+
```js
332+
module.exports = {
333+
//...
334+
resolve: {
335+
exportsFields: ['exports', 'myCompanyExports'],
336+
},
337+
};
338+
```
339+
276340
### resolve.extensionAlias
277341

278342
`object`
@@ -382,6 +446,23 @@ module.exports = {
382446
};
383447
```
384448

449+
### resolve.importsFields
450+
451+
`[string]`
452+
453+
Fields from `package.json` which are used to provide the internal requests of a package (requests starting with `#` are considered internal).
454+
455+
**webpack.config.js**
456+
457+
```js
458+
module.exports = {
459+
//...
460+
resolve: {
461+
importsFields: ['browser', 'module', 'main'],
462+
},
463+
};
464+
```
465+
385466
### resolve.mainFields
386467

387468
`[string]`
@@ -442,23 +523,6 @@ module.exports = {
442523
};
443524
```
444525

445-
### resolve.exportsFields
446-
447-
`[string] = ['exports']`
448-
449-
Fields in package.json that are used for resolving module requests. See [package-exports guideline](/guides/package-exports/) for more information.
450-
451-
**webpack.config.js**
452-
453-
```js
454-
module.exports = {
455-
//...
456-
resolve: {
457-
exportsFields: ['exports', 'myCompanyExports'],
458-
},
459-
};
460-
```
461-
462526
### resolve.modules
463527

464528
`[string] = ['node_modules']`
@@ -497,68 +561,38 @@ module.exports = {
497561
};
498562
```
499563

500-
### resolve.unsafeCache
501-
502-
`RegExp` `[RegExp]` `boolean: true`
503-
504-
Enable aggressive, but **unsafe**, caching of modules. Passing `true` will cache everything.
505-
506-
**webpack.config.js**
564+
### resolve.plugins
507565

508-
```js
509-
module.exports = {
510-
//...
511-
resolve: {
512-
unsafeCache: true,
513-
},
514-
};
515-
```
566+
[`[Plugin]`](/plugins/)
516567

517-
A regular expression, or an array of regular expressions, can be used to test file paths and only cache certain modules. For example, to only cache utilities:
568+
A list of additional resolve plugins which should be applied. It allows plugins such as [`DirectoryNamedWebpackPlugin`](https://www.npmjs.com/package/directory-named-webpack-plugin).
518569

519570
**webpack.config.js**
520571

521572
```js
522573
module.exports = {
523574
//...
524575
resolve: {
525-
unsafeCache: /src\/utilities/,
576+
plugins: [new DirectoryNamedWebpackPlugin()],
526577
},
527578
};
528579
```
529580

530-
W> Changes to cached paths may cause failure in rare cases.
531-
532-
### resolve.useSyncFileSystemCalls
581+
### resolve.preferAbsolute
533582

534583
`boolean`
535584

536-
Use synchronous filesystem calls for the resolver.
537-
538-
**webpack.config.js**
539-
540-
```js
541-
module.exports = {
542-
//...
543-
resolve: {
544-
useSyncFileSystemCalls: true,
545-
},
546-
};
547-
```
548-
549-
### resolve.plugins
550-
551-
[`[Plugin]`](/plugins/)
585+
<Badge text="5.13.0+" />
552586

553-
A list of additional resolve plugins which should be applied. It allows plugins such as [`DirectoryNamedWebpackPlugin`](https://www.npmjs.com/package/directory-named-webpack-plugin).
587+
Prefer absolute paths to [`resolve.roots`](#resolveroots) when resolving.
554588

555589
**webpack.config.js**
556590

557591
```js
558592
module.exports = {
559593
//...
560594
resolve: {
561-
plugins: [new DirectoryNamedWebpackPlugin()],
595+
preferAbsolute: true,
562596
},
563597
};
564598
```
@@ -592,143 +626,109 @@ const b = new URL('module/path', import.meta.url);
592626
const a = new URL('./module/path', import.meta.url);
593627
```
594628
595-
### resolve.preferAbsolute
596-
597-
`boolean`
629+
### resolve.restrictions
598630
599-
<Badge text="5.13.0+" />
631+
`[string, RegExp]`
600632
601-
Prefer absolute paths to [`resolve.roots`](#resolveroots) when resolving.
633+
A list of resolve restrictions to restrict the paths that a request can be resolved on.
602634
603635
**webpack.config.js**
604636
605637
```js
606638
module.exports = {
607639
//...
608640
resolve: {
609-
preferAbsolute: true,
641+
restrictions: [/\.(sass|scss|css)$/],
610642
},
611643
};
612644
```
613645
614-
### resolve.symlinks
615-
616-
`boolean = true`
646+
### resolve.roots
617647
618-
Whether to resolve symlinks to their symlinked location.
648+
`[string]`
619649
620-
When enabled, symlinked resources are resolved to their _real_ path, not their symlinked location. Note that this may cause module resolution to fail when using tools that symlink packages (like `npm link`).
650+
A list of directories where requests of server-relative URLs (starting with '/') are resolved, defaults to [`context` configuration option](/configuration/entry-context/#context). On non-Windows systems these requests are resolved as an absolute path first.
621651
622652
**webpack.config.js**
623653
624654
```js
655+
const fixtures = path.resolve(__dirname, 'fixtures');
625656
module.exports = {
626657
//...
627658
resolve: {
628-
symlinks: true,
659+
roots: [__dirname, fixtures],
629660
},
630661
};
631662
```
632663
633-
### resolve.cachePredicate
664+
### resolve.symlinks
634665
635-
`function(module) => boolean`
666+
`boolean = true`
636667
637-
A function which decides whether a request should be cached or not. An object is passed to the function with `path` and `request` properties. It must return a boolean.
668+
Whether to resolve symlinks to their symlinked location.
669+
670+
When enabled, symlinked resources are resolved to their _real_ path, not their symlinked location. Note that this may cause module resolution to fail when using tools that symlink packages (like `npm link`).
638671
639672
**webpack.config.js**
640673
641674
```js
642675
module.exports = {
643676
//...
644677
resolve: {
645-
cachePredicate: (module) => {
646-
// additional logic
647-
return true;
648-
},
678+
symlinks: true,
649679
},
650680
};
651681
```
652682
653-
### resolve.restrictions
683+
### resolve.unsafeCache
654684
655-
`[string, RegExp]`
685+
`RegExp` `[RegExp]` `boolean: true`
656686
657-
A list of resolve restrictions to restrict the paths that a request can be resolved on.
687+
Enable aggressive, but **unsafe**, caching of modules. Passing `true` will cache everything.
658688
659689
**webpack.config.js**
660690
661691
```js
662692
module.exports = {
663693
//...
664694
resolve: {
665-
restrictions: [/\.(sass|scss|css)$/],
695+
unsafeCache: true,
666696
},
667697
};
668698
```
669699
670-
### resolve.roots
671-
672-
`[string]`
673-
674-
A list of directories where requests of server-relative URLs (starting with '/') are resolved, defaults to [`context` configuration option](/configuration/entry-context/#context). On non-Windows systems these requests are resolved as an absolute path first.
700+
A regular expression, or an array of regular expressions, can be used to test file paths and only cache certain modules. For example, to only cache utilities:
675701
676702
**webpack.config.js**
677703
678704
```js
679-
const fixtures = path.resolve(__dirname, 'fixtures');
680705
module.exports = {
681706
//...
682707
resolve: {
683-
roots: [__dirname, fixtures],
708+
unsafeCache: /src\/utilities/,
684709
},
685710
};
686711
```
687712
688-
### resolve.importsFields
713+
W> Changes to cached paths may cause failure in rare cases.
689714
690-
`[string]`
715+
### resolve.useSyncFileSystemCalls
691716
692-
Fields from `package.json` which are used to provide the internal requests of a package (requests starting with `#` are considered internal).
717+
`boolean`
718+
719+
Use synchronous filesystem calls for the resolver.
693720
694721
**webpack.config.js**
695722
696723
```js
697724
module.exports = {
698725
//...
699726
resolve: {
700-
importsFields: ['browser', 'module', 'main'],
727+
useSyncFileSystemCalls: true,
701728
},
702729
};
703730
```
704731
705-
### resolve.byDependency
706-
707-
Configure resolve options by the type of module request.
708-
709-
- Type: `[type: string]: ResolveOptions`
710-
- Example:
711-
712-
```js
713-
module.exports = {
714-
// ...
715-
resolve: {
716-
byDependency: {
717-
// ...
718-
esm: {
719-
mainFields: ['browser', 'module'],
720-
},
721-
commonjs: {
722-
aliasFields: ['browser'],
723-
},
724-
url: {
725-
preferRelative: true,
726-
},
727-
},
728-
},
729-
};
730-
```
731-
732732
## resolveLoader
733733
734734
`object { modules [string] = ['node_modules'], extensions [string] = ['.js', '.json'], mainFields [string] = ['loader', 'main']}`

0 commit comments

Comments
 (0)