Skip to content

Commit 81275c9

Browse files
authored
refactor: deprecate customResolver in resolve.alias (#21476)
1 parent c367b62 commit 81275c9

4 files changed

Lines changed: 13 additions & 4 deletions

File tree

docs/config/shared-options.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ Directory to save cache files. Files in this directory are pre-bundled deps or s
9292
## resolve.alias
9393
9494
- **Type:**
95-
`Record<string, string> | Array<{ find: string | RegExp, replacement: string, customResolver?: ResolverFunction | ResolverObject }>`
95+
`Record<string, string> | Array<{ find: string | RegExp, replacement: string }>`
9696
9797
Defines aliases used to replace values in `import` or `require` statements. This works similar to [`@rollup/plugin-alias`](https://github.com/rollup/plugins/tree/master/packages/alias).
9898
@@ -119,7 +119,7 @@ resolve: {
119119
}
120120
```
121121

122-
### Array Format (`Array<{ find: string | RegExp, replacement: string, customResolver?: ResolverFunction | ResolverObject }>`)
122+
### Array Format (`Array<{ find: string | RegExp, replacement: string }>`)
123123

124124
The Array format allows specifying aliases as objects, which can be useful for complex key/value pairs.
125125

@@ -138,8 +138,6 @@ When `find` is a regular expression, the `replacement` can use [replacement patt
138138
{ find:/^(.*)\.js$/, replacement: '$1.alias' }
139139
```
140140

141-
`customResolver` option can be used to provide separate module resolution for an individual alias.
142-
143141
## resolve.dedupe
144142

145143
- **Type:** `string[]`

docs/guide/migration.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ The following options are deprecated and will be removed in the future:
328328
- `worker.rollupOptions`: renamed to `worker.rolldownOptions`
329329
- `build.commonjsOptions`: it is now no-op
330330
- `build.dynamicImportVarsOptions.warnOnError`: it is now no-op
331+
- `resolve.alias[].customResolver`: Use a custom plugin with `resolveId` hook instead
331332

332333
## General Changes [<Badge text="NRV" type="warning" />](#migration-from-v7)
333334

packages/vite/src/node/config.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,6 +1137,15 @@ function resolveResolveOptions(
11371137
),
11381138
)
11391139
}
1140+
if (alias.some((a) => a.customResolver)) {
1141+
logger.warn(
1142+
colors.yellow(
1143+
`\`resolve.alias\` contains an alias with \`customResolver\` option. ` +
1144+
`This is deprecated and will be removed in Vite 9. ` +
1145+
`Please use a custom plugin with a resolveId hook instead.`,
1146+
),
1147+
)
1148+
}
11401149

11411150
return resolveEnvironmentResolveOptions(
11421151
resolve,

packages/vite/src/types/alias.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export interface Alias {
3636
* Instructs the plugin to use an alternative resolving algorithm,
3737
* rather than the Rollup's resolver.
3838
* @default null
39+
* @deprecated Use a custom plugin with resolveId hook instead
3940
*/
4041
customResolver?: ResolverFunction | ResolverObject | null
4142
}

0 commit comments

Comments
 (0)