close
logologo
指南
配置
插件
API
社区
版本
更新日志
Rsbuild 0.x 文档
English
简体中文
指南
配置
插件
API
社区
更新日志
Rsbuild 0.x 文档
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
📝 在 GitHub 上编辑此页
上一页output.charset
下一页output.copy

#output.cleanDistPath

  • 类型:
type CleanDistPath = boolean | 'auto' | CleanDistPathObject;
  • 默认值: 'auto'

是否在构建开始前清理产物目录下的所有文件,产物目录为 output.distPath.root 的值。

#默认行为

output.cleanDistPath 的默认值为 'auto':

  • 在开发模式下,如果 dev.writeToDisk 的值为 false,则 Rsbuild 不会执行清理。
  • 在任意模式下,如果 output.distPath.root 为外部目录,或等于项目根目录时,Rsbuild 不会执行清理,这是为了避免误删其他目录的文件。
rsbuild.config.ts
export default {
  output: {
    distPath: {
      root: '../../some-dir',
    },
  },
};

#强制开关

你可以把 cleanDistPath 设置为 true 来强制开启,也可以设置为 false 来强制关闭该行为。

rsbuild.config.ts
export default {
  output: {
    cleanDistPath: true,
  },
};

#条件判断

如果你只需要在生产模式构建前清理文件,而在开发模式构建前不需要,那么可以配置为:

rsbuild.config.ts
export default {
  output: {
    cleanDistPath: process.env.NODE_ENV === 'production',
  },
};

#选项

output.cleanDistPath 支持配置为对象,以实现更细粒度的控制。

#enable

  • 类型: boolean | 'auto'
  • 默认值: 'auto'

是否在构建开始前清理产物目录下的所有文件。

rsbuild.config.ts
export default {
  output: {
    // 等价于 `cleanDistPath: true`
    cleanDistPath: {
      enable: true,
    },
  },
};

#keep

  • 类型: RegExp[]
  • 默认值: undefined

指定在产物目录下保留的文件。如果文件的绝对路径可以匹配到 keep 中的正则表达式,则该文件不会被删除。

例如,保留 dist/foo.json 文件:

rsbuild.config.ts
export default {
  output: {
    cleanDistPath: {
      keep: [/dist\/foo.json/],
    },
  },
};