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 Pageoutput.inlineScripts
Next Pageoutput.legalComments

#output.inlineStyles

  • Type:
type InlineChunkTestFunction = (params: {
  size: number;
  name: string;
}) => boolean;

type InlineChunkTest = RegExp | InlineChunkTestFunction;

type InlineChunkConfig =
  | boolean
  | InlineChunkTest
  | { enable?: boolean | 'auto'; test: InlineChunkTest };
  • Default: false

Whether to inline output style files (.css files) into HTML with <style> tags.

When this option is enabled, style files are no longer written to the dist directory and only exist inside the HTML file.

#Example

By default, the following output files are generated:

dist/html/main/index.html
dist/static/css/style.css
dist/static/js/main.js

After enabling the output.inlineStyles option:

export default {
  output: {
    inlineStyles: true,
  },
};

The output files of production build will become:

dist/html/main/index.html
dist/static/js/main.js

And dist/static/css/style.css will be inlined in index.html:

<html>
  <head>
    <style>
      /* content of dist/static/css/style.css */
    </style>
  </head>
  <body></body>
</html>
TIP

Setting inlineStyles: true is equivalent to setting inlineStyles.enable to 'auto'. This indicates that inline styles will only be enabled in production mode.

#Using RegExp

To inline part of the CSS files, set inlineStyles to a regular expression that matches the URL of the CSS file that needs to be inlined.

For example, to inline main.css into HTML, add the following configuration:

export default {
  output: {
    inlineStyles: /[\\/]main\.\w+\.css$/,
  },
};
TIP

Production filenames include a hash value by default, such as static/css/main.18a568e5.css. In regular expressions, use \w+ to match the hash.

#Using function

Set output.inlineStyles to a function that accepts the following parameters:

  • name: The filename, such as static/css/main.18a568e5.css.
  • size: The file size in bytes.

To inline assets smaller than 10 kB, add the following configuration:

export default {
  output: {
    inlineStyles({ size }) {
      return size < 10 * 1000;
    },
  },
};

#Options

#enable

  • Type: boolean | 'auto'
  • Default: false

Whether to enable the inline styles feature. If set to 'auto', it will be enabled when the mode is 'production'.

export default {
  output: {
    inlineStyles: {
      enable: 'auto',
      test: /[\\/]main\.\w+\.css$/,
    },
  },
};

#test

  • Type: RegExp | ((params: { size: number; name: string }) => boolean)

The regular expression or function to match the CSS files that need to be inlined.

export default {
  output: {
    inlineStyles: {
      enable: true,
      test: /[\\/]main\.\w+\.css$/,
    },
  },
};