Skip to content

Commit 4c82806

Browse files
committed
Improve resolve docs
1 parent cee88fb commit 4c82806

File tree

1 file changed

+55
-30
lines changed

1 file changed

+55
-30
lines changed

content/configuration/resolve.md

Lines changed: 55 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ contributors:
66
- skipjack
77
- SpaceK33z
88
- pksjce
9+
- sebastiandeutsch
910
---
1011

1112
These options change how modules are resolved. webpack provides reasonable defaults, but it is possible to change the resolving in detail.
@@ -94,27 +95,33 @@ aliasFields: ["browser"]
9495

9596
`array`
9697

97-
Default: `["package.json"]`
98+
The JSON files to use for descriptions. Default:
9899

99-
The JSON files to use for descriptions.
100+
```js
101+
descriptionFiles: ["package.json"]
102+
```
100103

101104

102105
## `resolve.enforceExtension`
103106

104-
`bool`
107+
`boolean`
105108

106-
Default: `false`
109+
If `true`, it will not allow extension-less files. So by default `require('./foo')` works if `./foo` has a `.js` extension, but with this enabled only `require('./foo.js')` will work. Default:
107110

108-
If false it will also try to use no extension from above.
111+
```js
112+
enforceExtension: false
113+
```
109114

110115

111116
## `resolve.enforceModuleExtension`
112117

113-
`bool`
118+
`boolean`
114119

115-
Default: `false`
120+
Whether to require to use an extension for modules (e.g. loaders). Default:
116121

117-
If false it's also try to use no module extension from above.
122+
```js
123+
enforceModuleExtension: false
124+
```
118125

119126

120127
## `resolve.extensions`
@@ -124,7 +131,7 @@ If false it's also try to use no module extension from above.
124131
Automatically resolve certain extensions. This defaults to:
125132

126133
```js
127-
extensions: [ ".js", ".json" ]
134+
extensions: [".js", ".json"]
128135
```
129136

130137
which is what enables users to leave off the extension when importing:
@@ -174,9 +181,11 @@ This means that when we `import * as D3 from "d3"` this will really resolve to t
174181

175182
`array`
176183

177-
Default: `["index"]`
184+
The filename to be used while resolving directories. Default:
178185

179-
The filename to be used while resolving directories.
186+
```js
187+
mainFiles: ["index"]
188+
```
180189

181190

182191
## `resolve.modules`
@@ -206,18 +215,26 @@ modules: [path.resolve(__dirname, "src"), "node_modules"]
206215

207216
## `resolve.resolveToContext`
208217

209-
`bool`
218+
`boolean`
210219

211-
Default: `false`
220+
If `true`, trying to resolve a context to its absolute path ends when a directory is found. Default:
212221

213-
If true, trying to resolve a context to its absolute path ends when a directory is found.
222+
```js
223+
resolveToContext: false
224+
```
214225

215226

216227
## `resolve.unsafeCache`
217228

218229
`regex` `array` `boolean`
219230

220-
Enable aggressive, but **unsafe**, caching of modules. Passing `true` will cache everything. 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:
231+
Enable aggressive, but **unsafe**, caching of modules. Passing `true` will cache everything. Default:
232+
233+
```js
234+
unsafeCache: true
235+
```
236+
237+
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:
221238

222239
```js
223240
unsafeCache: /src\/utilities/
@@ -230,9 +247,7 @@ W> Changes to cached paths may cause failure in rare cases.
230247

231248
`object`
232249

233-
This set of options is identical to the `resolve` set above, but is used only to resolve webpack's [loader](/concepts/loaders) packages.
234-
235-
Default:
250+
This set of options is identical to the `resolve` set above, but is used only to resolve webpack's [loader](/concepts/loaders) packages. Default:
236251

237252
```js
238253
{
@@ -244,32 +259,42 @@ Default:
244259

245260
T> Note that you can use alias here and other features familiar from resolve. For example `{ txt: 'raw-loader' }` would shim `txt!templates/demo.txt` to use `raw-loader`.
246261

247-
## `resolveLoader.moduleTemplates`
262+
263+
## `resolveLoader.moduleExtensions`
248264

249265
`array`
250266

251-
That's a `resolveLoader` only property.It describes alternatives for the module name that are tried.
267+
The extensions which are tried when resolving a module (e.g. loaders). By default this is an empty array.
252268

253-
Default: `["*-webpack-loader", "*-web-loader", "*-loader", "*"]`
269+
If you want to use loaders without the `-loader` suffix, you can use this:
254270

271+
```js
272+
moduleExtensions: ['-loaders']
273+
```
255274

256-
## `resolveLoader.moduleExtensions`
257275

258-
`array`
276+
## `resolve.plugins`
259277

260-
Example: `['-loaders']`
278+
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).
261279

262-
These extensions which are tried when resolving a module.
280+
```js
281+
plugins: [new DirectoryNamedWebpackPlugin()]
282+
```
263283

264284

265-
## `resolve.plugins`
285+
## `resolve.symlinks`
266286

267-
?> Description
287+
`boolean`
268288

269-
## `resolve.symlinks`
289+
Whether to resolve symlinks to their symlinked location. Defaults to `true`.
270290

271-
?> Description
272291

273292
## `resolve.cachePredicate`
274293

275-
?> Description
294+
`function`
295+
296+
A function which decides wheter a request should be cached or not. An object is passed to the function with `path` and `request` properties. Default:
297+
298+
```js
299+
cachePredicate: function() { return true }
300+
```

0 commit comments

Comments
 (0)