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.inlineStyles
下一页output.manifest

#output.legalComments

  • 类型: 'linked' | 'inline' | 'none'
  • 默认值: 'linked'

配置 legal comments 的处理方式。

#什么是 legal comments?

Legal comments 是 JS 或 CSS 文件中的一些特殊注释,这些注释包含 @license 或 @preserve,或是以 //! 开头。默认情况下,这些注释保留在输出文件中,因为这遵循了代码原作者的意图。

例如 React 的 LICENSE 注释:

/**
 * @license React
 * react.production.js
 *
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */

#可选值

你可以通过 legalComments 来配置如何处理 legal comments:

#linked

将所有 legal comments 移至 *.LICENSE.txt 文件,并通过注释链接到它们。

rsbuild.config.js
export default {
  output: {
    legalComments: 'linked',
  },
};

.LICENSE.txt 文件不会被页面加载,因此它们不会影响页面的性能。

#inline

保留所有 legal comments 在代码的原始位置。这可能会导致输出文件的体积变大。

rsbuild.config.js
export default {
  output: {
    legalComments: 'inline',
  },
};

#none

移除所有 legal comments。

rsbuild.config.js
export default {
  output: {
    legalComments: 'none',
  },
};
TIP

移除 license 注释可能会违反部分开源软件的许可协议要求。在使用此选项前,请确认你具有移除这些注释的权利。