Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(resolve): and wildcard alias configuration #7505

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading