diff --git a/docs/config/shared-options.md b/docs/config/shared-options.md index 5c53449ce53f0f..34eb99b8561379 100644 --- a/docs/config/shared-options.md +++ b/docs/config/shared-options.md @@ -92,7 +92,7 @@ Directory to save cache files. Files in this directory are pre-bundled deps or s ## resolve.alias - **Type:** - `Record | Array<{ find: string | RegExp, replacement: string, customResolver?: ResolverFunction | ResolverObject }>` + `Record | Array<{ find: string | RegExp, replacement: string }>` 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). @@ -119,7 +119,7 @@ resolve: { } ``` -### Array Format (`Array<{ find: string | RegExp, replacement: string, customResolver?: ResolverFunction | ResolverObject }>`) +### Array Format (`Array<{ find: string | RegExp, replacement: string }>`) The Array format allows specifying aliases as objects, which can be useful for complex key/value pairs. @@ -138,8 +138,6 @@ When `find` is a regular expression, the `replacement` can use [replacement patt { find:/^(.*)\.js$/, replacement: '$1.alias' } ``` -`customResolver` option can be used to provide separate module resolution for an individual alias. - ## resolve.dedupe - **Type:** `string[]` diff --git a/docs/guide/migration.md b/docs/guide/migration.md index e82bd7630a740b..49a79edf76571c 100644 --- a/docs/guide/migration.md +++ b/docs/guide/migration.md @@ -328,6 +328,7 @@ The following options are deprecated and will be removed in the future: - `worker.rollupOptions`: renamed to `worker.rolldownOptions` - `build.commonjsOptions`: it is now no-op - `build.dynamicImportVarsOptions.warnOnError`: it is now no-op +- `resolve.alias[].customResolver`: Use a custom plugin with `resolveId` hook instead ## General Changes [](#migration-from-v7) diff --git a/packages/vite/src/node/config.ts b/packages/vite/src/node/config.ts index 2273eb36b49b95..d338c2cec28ab7 100644 --- a/packages/vite/src/node/config.ts +++ b/packages/vite/src/node/config.ts @@ -1099,6 +1099,15 @@ function resolveResolveOptions( ), ) } + if (alias.some((a) => a.customResolver)) { + logger.warn( + colors.yellow( + `\`resolve.alias\` contains an alias with \`customResolver\` option. ` + + `This is deprecated and will be removed in Vite 9. ` + + `Please use a custom plugin with a resolveId hook instead.`, + ), + ) + } return resolveEnvironmentResolveOptions( resolve, diff --git a/packages/vite/src/types/alias.d.ts b/packages/vite/src/types/alias.d.ts index 0e3b94b5c4a903..3ed0b5f77361ab 100644 --- a/packages/vite/src/types/alias.d.ts +++ b/packages/vite/src/types/alias.d.ts @@ -36,6 +36,7 @@ export interface Alias { * Instructs the plugin to use an alternative resolving algorithm, * rather than the Rollup's resolver. * @default null + * @deprecated Use a custom plugin with resolveId hook instead */ customResolver?: ResolverFunction | ResolverObject | null }