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
Copy file name to clipboardExpand all lines: content/concepts/module-resolution.md
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,20 +10,20 @@ A resolver is a library which helps in locating a module by its absolute path.
10
10
A module can be required as a dependency from another module as:
11
11
12
12
```js
13
-
importmodulefrom'path/to/module'
13
+
importfoofrom'path/to/module'
14
14
// or
15
15
require('path/to/module')
16
16
```
17
17
18
18
The dependency module can be from the application code or a third party library. The resolver helps
19
-
webpack find the module code that needs to be included in the bundle for every such `require`/`import` statement.
19
+
webpack finds the module code that needs to be included in the bundle for every such `require`/`import` statement.
20
20
webpack uses [enhanced-resolve](https://github.com/webpack/enhanced-resolve) to resolve file paths while bundling modules.
21
21
22
22
## Resolving rules in webpack
23
23
24
24
Using `enhanced-resolve`, webpack can resolve three kinds of file paths:
25
25
26
-
### 1. Absolute paths
26
+
### Absolute paths
27
27
28
28
```js
29
29
import"/home/me/file";
@@ -33,7 +33,7 @@ import "C:\\Users\\me\\file";
33
33
34
34
Since we already have the absolute path to the file, no further resolution is required.
35
35
36
-
### 2. Relative paths
36
+
### Relative paths
37
37
38
38
```js
39
39
import"../src/file1";
@@ -42,7 +42,7 @@ import "./file2";
42
42
43
43
In this case, the directory of the resource file where the `import` or `require` occurs is taken to be the context directory. The relative path specified in the `import/require` is joined to this context path to produce the absolute path to the module.
44
44
45
-
### 3. Module paths
45
+
### Module paths
46
46
47
47
```js
48
48
import"module";
@@ -61,7 +61,7 @@ If the path points to a folder, then the following steps are taken to find the r
61
61
* If there is no `package.json` or if the main fields do not return a valid path, file names specified in the [`resolve.mainFiles`](/configuration/resolve/#resolve-mainfiles) configuration option are looked for in order, to see if a matching filename exists in the imported/required directory .
62
62
* The file extension is then resolved in a similar way using the `resolve.extensions` option.
63
63
64
-
Webpack provides reasonable [defaults](/configuration/resolve) for these options depending on your build target.
64
+
webpack provides reasonable [defaults](/configuration/resolve) for these options depending on your build target.
0 commit comments