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
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
+
returntrue;
215
+
},
216
+
},
217
+
};
218
+
```
219
+
173
220
### resolve.cacheWithContext
174
221
175
222
`boolean`
@@ -273,6 +320,23 @@ module.exports = {
273
320
};
274
321
```
275
322
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
+
276
340
### resolve.extensionAlias
277
341
278
342
`object`
@@ -382,6 +446,23 @@ module.exports = {
382
446
};
383
447
```
384
448
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
+
385
466
### resolve.mainFields
386
467
387
468
`[string]`
@@ -442,23 +523,6 @@ module.exports = {
442
523
};
443
524
```
444
525
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
-
462
526
### resolve.modules
463
527
464
528
`[string] = ['node_modules']`
@@ -497,68 +561,38 @@ module.exports = {
497
561
};
498
562
```
499
563
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
507
565
508
-
```js
509
-
module.exports= {
510
-
//...
511
-
resolve: {
512
-
unsafeCache:true,
513
-
},
514
-
};
515
-
```
566
+
[`[Plugin]`](/plugins/)
516
567
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).
518
569
519
570
**webpack.config.js**
520
571
521
572
```js
522
573
module.exports= {
523
574
//...
524
575
resolve: {
525
-
unsafeCache:/src\/utilities/,
576
+
plugins: [newDirectoryNamedWebpackPlugin()],
526
577
},
527
578
};
528
579
```
529
580
530
-
W> Changes to cached paths may cause failure in rare cases.
531
-
532
-
### resolve.useSyncFileSystemCalls
581
+
### resolve.preferAbsolute
533
582
534
583
`boolean`
535
584
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
+
<Badgetext="5.13.0+" />
552
586
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.
554
588
555
589
**webpack.config.js**
556
590
557
591
```js
558
592
module.exports= {
559
593
//...
560
594
resolve: {
561
-
plugins: [newDirectoryNamedWebpackPlugin()],
595
+
preferAbsolute:true,
562
596
},
563
597
};
564
598
```
@@ -592,143 +626,109 @@ const b = new URL('module/path', import.meta.url);
592
626
consta=newURL('./module/path', import.meta.url);
593
627
```
594
628
595
-
### resolve.preferAbsolute
596
-
597
-
`boolean`
629
+
### resolve.restrictions
598
630
599
-
<Badge text="5.13.0+" />
631
+
`[string, RegExp]`
600
632
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.
602
634
603
635
**webpack.config.js**
604
636
605
637
```js
606
638
module.exports= {
607
639
//...
608
640
resolve: {
609
-
preferAbsolute:true,
641
+
restrictions: [/\.(sass|scss|css)$/],
610
642
},
611
643
};
612
644
```
613
645
614
-
### resolve.symlinks
615
-
616
-
`boolean =true`
646
+
### resolve.roots
617
647
618
-
Whether to resolve symlinks to their symlinked location.
648
+
`[string]`
619
649
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.
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`).
638
671
639
672
**webpack.config.js**
640
673
641
674
```js
642
675
module.exports= {
643
676
//...
644
677
resolve: {
645
-
cachePredicate: (module) => {
646
-
// additional logic
647
-
returntrue;
648
-
},
678
+
symlinks:true,
649
679
},
650
680
};
651
681
```
652
682
653
-
### resolve.restrictions
683
+
### resolve.unsafeCache
654
684
655
-
`[string, RegExp]`
685
+
`RegExp``[RegExp]``boolean:true`
656
686
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.
658
688
659
689
**webpack.config.js**
660
690
661
691
```js
662
692
module.exports= {
663
693
//...
664
694
resolve: {
665
-
restrictions: [/\.(sass|scss|css)$/],
695
+
unsafeCache:true,
666
696
},
667
697
};
668
698
```
669
699
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:
0 commit comments