resolve
- Type:
optionalresolve:object
Options for built-in module resolution feature.
alias?
- Type:
optionalalias:Record<string,string|false|string[]>
Substitute one package for another.
One use case for this feature is replacing a node-only package with a browser-friendly package in third-party code that you don't control.
Example
resolve: {
alias: {
'@': '/src',
'utils': './src/utils',
}
}WARNING
resolve.alias will not call resolveId hooks of other plugin. If you want to call resolveId hooks of other plugin, use viteAliasPlugin from rolldown/experimental instead. You could find more discussion in this issue
aliasFields?
- Type:
optionalaliasFields:string[][]
Fields in package.json to check for aliased paths.
This option is expected to be used for browser field support.
Default
[['browser']]forbrowserplatform[]for other platforms
conditionNames?
- Type:
optionalconditionNames:string[]
Condition names to use when resolving exports in package.json.
Default
Defaults based on platform and import kind:
browserplatform["import", "browser", "default"]for import statements["require", "browser", "default"]for require() calls
nodeplatform["import", "node", "default"]for import statements["require", "node", "default"]for require() calls
neutralplatform["import", "default"]for import statements["require", "default"]for require() calls
exportsFields?
- Type:
optionalexportsFields:string[][]
Fields in package.json to check for exports.
Default
[['exports']]
extensionAlias?
- Type:
optionalextensionAlias:Record<string,string[]>
Map of extensions to alternative extensions.
With writing import './foo.js' in a file, you want to resolve it to foo.ts instead of foo.js. You can achieve this by setting: extensionAlias: { '.js': ['.ts', '.js'] }.
extensions?
- Type:
optionalextensions:string[]
Extensions to try when resolving files. These are tried in order from first to last.
Default
['.tsx', '.ts', '.jsx', '.js', '.json']
mainFields?
- Type:
optionalmainFields:string[]
Fields in package.json to check for entry points.
Default
Defaults based on platform:
nodeplatform:['main', 'module']browserplatform:['browser', 'module', 'main']neutralplatform:[]
mainFiles?
- Type:
optionalmainFiles:string[]
Filenames to try when resolving directories.
Default
['index']modules?
- Type:
optionalmodules:string[]
Directories to search for modules.
Default
['node_modules']symlinks?
- Type:
optionalsymlinks:boolean
Whether to follow symlinks when resolving modules.
Default
truetsconfigFilename?
- Type:
optionaltsconfigFilename:string
Deprecated
Use the top-level tsconfig option instead.