Skip to content

resolve

  • Type: optional resolve: object

Options for built-in module resolution feature.

alias?

  • Type: optional alias: 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

js
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: optional aliasFields: string[][]

Fields in package.json to check for aliased paths.

This option is expected to be used for browser field support.

Default

  • [['browser']] for browser platform
  • [] for other platforms

conditionNames?

  • Type: optional conditionNames: string[]

Condition names to use when resolving exports in package.json.

Default

Defaults based on platform and import kind:

  • browser platform
    • ["import", "browser", "default"] for import statements
    • ["require", "browser", "default"] for require() calls
  • node platform
    • ["import", "node", "default"] for import statements
    • ["require", "node", "default"] for require() calls
  • neutral platform
    • ["import", "default"] for import statements
    • ["require", "default"] for require() calls

exportsFields?

  • Type: optional exportsFields: string[][]

Fields in package.json to check for exports.

Default

[['exports']]

extensionAlias?

  • Type: optional extensionAlias: 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: optional extensions: string[]

Extensions to try when resolving files. These are tried in order from first to last.

Default

['.tsx', '.ts', '.jsx', '.js', '.json']

mainFields?

  • Type: optional mainFields: string[]

Fields in package.json to check for entry points.

Default

Defaults based on platform:

  • node platform: ['main', 'module']
  • browser platform: ['browser', 'module', 'main']
  • neutral platform: []

mainFiles?

  • Type: optional mainFiles: string[]

Filenames to try when resolving directories.

Default

ts
['index']

modules?

  • Type: optional modules: string[]

Directories to search for modules.

Default

ts
['node_modules']
  • Type: optional symlinks: boolean

Whether to follow symlinks when resolving modules.

Default

ts
true

tsconfigFilename?

  • Type: optional tsconfigFilename: string

Deprecated

Use the top-level tsconfig option instead.

Released under the MIT License.