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 Pageserver.proxy
Next Pageserver.strictPort

#server.publicDir

  • Type:
type PublicDirOptions = {
  name?: string;
  copyOnBuild?: boolean | 'auto';
  watch?: boolean;
};
type PublicDir = false | PublicDirOptions | PublicDirOptions[];
  • Default:
const defaultValue = {
  name: 'public',
  copyOnBuild: 'auto',
  watch: false,
};

By default, Rsbuild uses the public directory for serving public assets. Files in this directory are served at server.base path (default /).

Related document: Public Folder.

#Options

#name

  • Type: string
  • Default: 'public'

The name of the public directory. The value of name can be set to a relative path or an absolute path. Relative path will be resolved relative to the project root directory.

  • Relative path example:
export default {
  server: {
    publicDir: {
      name: '../some-public',
    },
  },
};
  • Absolute path example:
import path from 'node:path';

export default {
  server: {
    publicDir: {
      name: path.join(__dirname, '../some-public'),
    },
  },
};

#copyOnBuild

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

Whether to copy files from the public directory to the dist directory on production build.

  • true: copy files.
  • false: do not copy files.
  • 'auto': if output.target is not 'node', copy files, otherwise do not copy.
TIP

During dev builds, if you need to copy some static assets to the output directory, you can use the output.copy option instead.

#Disable

For example, disable copyOnBuild:

export default {
  server: {
    publicDir: {
      copyOnBuild: false,
    },
  },
};

Note that setting the value of copyOnBuild to false means that when you run rsbuild preview for a production preview, you will not be able to access the corresponding static resources.

#Node target

By default, when output.target is 'node', Rsbuild will not copy files from the public directory.

You can set copyOnBuild to true to copy files for the node target:

export default {
  output: {
    target: 'node',
  },
  server: {
    publicDir: {
      copyOnBuild: true,
    },
  },
};

#Multiple environments

When performing multi-environment builds, Rsbuild copies files from the public directory to the output directory of each environment. If there are nested output directories, files will only be copied to the root of the output directory. For example:

  • The distDir of the web environment is dist, and the distDir of the web1 environment is dist/web1. Due to the nested relationship between dist and dist/web1, the public directory files are only copied to the dist directory.
  • The distDir of the esm environment is dist/esm, and the distDir of the cjs environment is dist/cjs. Since there is no nesting relationship between dist/esm and dist/cjs, the public directory files will be copied to both the dist/esm and dist/cjs directories.

#watch

  • Type: boolean
  • Default: false

Whether to watch the public directory and reload the page when the files change.

Setting watch to true allows the dev server to watch changes to files in the specified public directory and reload the page when the files are changed:

export default {
  server: {
    publicDir: {
      watch: true,
    },
  },
};

Note that the watch option is only valid in development mode. If dev.hmr and dev.liveReload are both set to false, watch will be ignored.

#Multiple directories

The server.publicDir can be configured as an array, allowing you to serve multiple directories as static assets folders:

export default {
  server: {
    publicDir: [
      {
        name: 'public',
      },
      {
        name: 'assets',
        watch: false,
      },
    ],
  },
};

#Disabled

You can set publicDir to false to disable the static assets serving:

export default {
  server: {
    publicDir: false,
  },
};