Skip to content

Commit

Permalink
docs(resolve): and wildcard alias configuration (#7505)
Browse files Browse the repository at this point in the history
  • Loading branch information
sapenlei authored Feb 7, 2025
1 parent 6240756 commit c1ac637
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/content/configuration/resolve.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ contributors:
- chenxsan
- jamesgeorge007
- snitin315
- sapenlei
---

These options change how modules are resolved. Webpack provides reasonable defaults, but it is possible to change the resolving in detail. Have a look at [Module Resolution](/concepts/module-resolution) for more explanation of how the resolver works.
Expand Down Expand Up @@ -97,6 +98,28 @@ import Test1 from 'xyz'; // Exact match, so path/to/file.js is resolved and impo
import Test2 from 'xyz/file.js'; // Not an exact match, normal resolution takes place
```

You can also use wildcards (`*`) in your alias configuration to create more flexible mappings:

**webpack.config.js**

```js
module.exports = {
//...
resolve: {
alias: {
'@*': path.resolve(__dirname, 'src/*'), // maps @something to path/to/something
},
},
};
```

This allows you to use imports like:

```js
import Component from '@components/Button';
import utils from '@utils/helpers';
```

The following table explains other cases:

| `alias:` | `import 'xyz'` | `import 'xyz/file.js'` |
Expand Down

0 comments on commit c1ac637

Please sign in to comment.