close
logologo
Guide
Config
Plugin
API
Community
Version
Changelog
Rsbuild 0.x Doc
English
简体中文
Guide
Config
Plugin
API
Community
Changelog
Rsbuild 0.x Doc
English
简体中文
logologo
Overview
root
mode
plugins
logLevel
environments

dev

dev.assetPrefix
dev.browserLogs
dev.cliShortcuts
dev.client
dev.hmr
dev.lazyCompilation
dev.liveReload
dev.progressBar
dev.setupMiddlewares
dev.watchFiles
dev.writeToDisk

resolve

resolve.aliasStrategy
resolve.alias
resolve.conditionNames
resolve.dedupe
resolve.extensions
resolve.mainFields

source

source.assetsInclude
source.decorators
source.define
source.entry
source.exclude
source.include
source.preEntry
source.transformImport
source.tsconfigPath

output

output.assetPrefix
output.charset
output.cleanDistPath
output.copy
output.cssModules
output.dataUriLimit
output.distPath
output.emitAssets
output.emitCss
output.externals
output.filenameHash
output.filename
output.injectStyles
output.inlineScripts
output.inlineStyles
output.legalComments
output.manifest
output.minify
output.module
output.overrideBrowserslist
output.polyfill
output.sourceMap
output.target

html

html.appIcon
html.crossorigin
html.favicon
html.inject
html.meta
html.mountId
html.outputStructure
html.scriptLoading
html.tags
html.templateParameters
html.template
html.title

server

server.base
server.compress
server.cors
server.headers
server.historyApiFallback
server.host
server.htmlFallback
server.https
server.middlewareMode
server.open
server.port
server.printUrls
server.proxy
server.publicDir
server.strictPort

security

security.nonce
security.sri

tools

tools.bundlerChain
tools.cssExtract
tools.cssLoader
tools.htmlPlugin
tools.lightningcssLoader
tools.postcss
tools.rspack
tools.styleLoader
tools.swc

performance

performance.buildCache
performance.bundleAnalyze
performance.chunkSplit
performance.dnsPrefetch
performance.preconnect
performance.prefetch
performance.preload
performance.printFileSize
performance.profile
performance.removeConsole
performance.removeMomentLocale

moduleFederation

moduleFederation.options
📝 Edit this page on GitHub
Previous Pagedev.writeToDisk
Next Pageresolve.alias

#resolve.aliasStrategy

  • Type: 'prefer-tsconfig' | 'prefer-alias'
  • Default: 'prefer-tsconfig'
  • Version: >=1.1.7

Set the strategy for path alias resolution, to control the priority relationship between the paths option in tsconfig.json and the resolve.alias option of Rsbuild.

TIP

See Path aliases for the differences between the paths option in tsconfig.json and the resolve.alias option of Rsbuild.

#prefer-tsconfig

By default, resolve.aliasStrategy is set to 'prefer-tsconfig'. In this case, both the paths option in tsconfig.json and the alias option in the bundler will take effect, but the paths option in tsconfig has a higher priority.

For example, if the following configurations are set at the same time:

  • tsconfig paths:
tsconfig.json
{
  "compilerOptions": {
    "paths": {
      "@common/*": ["./src/common-1/*"]
    }
  }
}
  • resolve.alias:
export default {
  resolve: {
    alias: {
      '@common': './src/common-2',
      '@utils': './src/utils',
    },
  },
};

Since the tsconfig paths have a higher priority, the following will happen:

  • @common will use the value defined in tsconfig paths, pointing to ./src/common-1
  • @utils will use the value defined in resolve.alias, pointing to ./src/utils

#prefer-alias

If the value of resolve.aliasStrategy is set to prefer-alias, the paths option in tsconfig.json will only be used to provide TypeScript type definitions and will not affect the bundling result. In this case, the bundler will only read the alias option as the path alias.

export default {
  resolve: {
    aliasStrategy: 'prefer-alias',
  },
};

For example, if the following configurations are set at the same time:

  • tsconfig paths:
tsconfig.json
{
  "compilerOptions": {
    "paths": {
      "@common/*": ["./src/common-1/*"],
      "@utils/*": ["./src/utils/*"]
    }
  }
}
  • resolve.alias:
export default {
  resolve: {
    alias: {
      '@common': './src/common-2',
    },
  },
};

Since the tsconfig paths are only used to provide types, only the @common alias will be effective, pointing to the ./src/common-2 directory.

In most cases, you do not need to use prefer-alias, but you can consider using it if you need to dynamically generate some alias configurations. For example, generating the alias option based on environment variables:

export default {
  resolve: {
    alias: {
      '@common':
        process.env.NODE_ENV === 'production'
          ? './src/common-prod'
          : './src/common-dev',
    },
  },
};