logo
  • Guide
  • Config
  • Plugin
  • API
  • Examples
  • Community
  • Modern.js 2.x Docs
  • English
    • 简体中文
    • English
    • Configuration
      dev
      assetPrefix
      beforeStartUrl
      client
      hmr
      host
      https
      lazyCompilation
      liveReload
      progressBar
      server
      setupMiddlewares
      startUrl
      watchFiles
      writeToDisk
      bff
      crossProject
      prefix
      html
      appIcon
      crossorigin
      favicon
      inject
      meta
      mountId
      outputStructure
      scriptLoading
      tags
      templateParameters
      template
      title
      tools
      autoprefixer
      babel
      bundlerChain
      cssExtract
      cssLoader
      devServer
      htmlPlugin
      less
      lightningcssLoader
      minifyCss
      postcss
      rspack
      sass
      styleLoader
      swc
      tsChecker
      source
      aliasStrategy
      alias
      configDir
      decorators
      define
      disableDefaultEntries
      enableAsyncEntry
      entriesDir
      entries
      exclude
      globalVars
      include
      mainEntryName
      preEntry
      transformImport
      resolve
      aliasStrategy
      alias
      conditionNames
      dedupe
      extensions
      server
      baseUrl
      port
      publicRoutes
      routes
      ssrByEntries
      ssr
      output
      assetPrefix
      assetsRetry
      charset
      cleanDistPath
      convertToRem
      copy
      cssModules
      dataUriLimit
      disableCssModuleExtension
      disableInlineRuntimeChunk
      disableSvgr
      disableTsChecker
      distPath
      enableAssetManifest
      enableCssModuleTSDeclaration
      disableInlineRouteManifests
      externals
      filenameHash
      filename
      injectStyles
      inlineScripts
      inlineStyles
      legalComments
      minify
      overrideBrowserslist
      polyfill
      sourceMap
      splitRouteChunks
      ssg
      ssgByEntries
      svgDefaultExport
      tempDir
      plugins
      security
      checkSyntax
      nonce
      sri
      runtime
      Introduce
      plugins
      router
      performance
      buildCache
      bundleAnalyze
      chunkSplit
      dnsPrefetch
      preconnect
      prefetch
      preload
      printFileSize
      profile
      removeConsole
      removeMomentLocale
      experiments
      sourceBuild
      builderPlugins
      📝 Edit this page
      Previous pageprogressBarNext pagesetupMiddlewares

      #dev.server

      • Type: Object
      • Default: {}

      The config of DevServer can be modified through dev.server.

      #compress

      • Type: boolean
      • Default: true

      Whether to enable gzip compression for served static assets.

      If you want to disable the gzip compression, you can set compress to false:

      export default {
        dev: {
          server: {
            compress: false,
          },
        },
      };

      For more details, please refer to the Rsbuild - server.compress documentation.

      #headers

      • Type: Record<string, string>
      • Default: undefined

      Adds headers to all responses.

      export default {
        dev: {
          server: {
            headers: {
              'X-Custom-Foo': 'bar',
            },
          },
        },
      };

      For more details, please refer to the Rsbuild - server.headers documentation.

      #historyApiFallback

      • Type: boolean | ConnectHistoryApiFallbackOptions
      • Default: false

      The index.html page will likely have to be served in place of any 404 responses. Enable dev.server.historyApiFallback by setting it to true:

      export default {
        dev: {
          server: {
            historyApiFallback: true,
          },
        },
      };

      For more configuration options, please refer to the Rsbuild - server.historyApiFallback documentation.

      #watch

      • Type: boolean
      • Default: true

      Whether to watch files change in directories such as mock/, server/, api/.

      For more details, please refer to the Rsbuild - dev.watchFiles documentation.

      #cors

      • Type: boolean | import('cors').CorsOptions

      Configure CORS (Cross-Origin Resource Sharing) for the development server.

      The default configuration for cors in Modern.js follows Rsbuild's defaults:

      const defaultAllowedOrigins =
        /^https?:\/\/(?:(?:[^:]+\.)?localhost|127\.0\.0\.1|\[::1\])(?::\d+)?$/;
      
      const defaultOptions = {
        // Default allowed:
        // - localhost
        // - 127.0.0.1
        // - [::1]
        origin: defaultAllowedOrigins
      };

      For more configuration options and detailed usage, please refer to the Rsbuild - server.cors documentation.