logo
  • Guide
  • Config
  • Plugin
  • API
  • Examples
  • Community
  • Modern.js 2.x Docs
  • English
    • 简体中文
    • English
    • Configuration
      dev
      assetPrefix
      beforeStartUrl
      client
      hmr
      host
      https
      lazyCompilation
      liveReload
      port
      progressBar
      setupMiddlewares
      startUrl
      watchFiles
      writeToDisk
      bff
      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 pagecleanDistPathNext pagecopy

      #output.convertToRem

      • Type: boolean | object
      • Default: false

      By setting output.convertToRem, Modern.js can do the following things:

      • Convert px to rem in CSS.
      • Insert runtime code into the HTML template to set the fontSize of the root element.

      #Boolean Type

      If output.convertToRem is set to true, Rem processing capability will be turned on.

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

      At this point, the rem configuration defaults as follows:

      {
        enableRuntime: true,
        rootFontSize: 50,
        screenWidth: 375,
        rootFontSize: 50,
        maxRootFontSize: 64,
        widthQueryKey: '',
        excludeEntries: [],
        supportLandscape: false,
        useRootFontSizeBeyondMax: false,
        pxtorem: {
          rootValue: 50,
          unitPrecision: 5,
          propList: ['*'],
        }
      }

      #Object Type

      When the value of output.convertToRem is object type, Modern.js will perform Rem processing based on the current configuration.

      options:

      NameTypeDefaultDescription
      enableRuntimebooleantrueWhether to generate runtime code to calculate and set the font size of the root element
      inlineRuntimebooleantrueWhether to inline the runtime code to HTML. If set to false, the runtime code will be extracted into a separate convert-rem.[version].js file and output to the dist directory
      rootFontSizenumber50The root element font size
      maxRootFontSizenumber64The root element max font size
      widthQueryKeystring'' Get clientWidth from the url query based on widthQueryKey
      screenWidthnumber375The screen width for UI design drawings (Usually, fontSize = (clientWidth * rootFontSize) / screenWidth)
      excludeEntriesstring[][]To exclude some page entries from injecting runtime code, it is usually used with pxtorem.exclude
      supportLandscapebooleanfalseUse height to calculate rem in landscape
      useRootFontSizeBeyondMaxbooleanfalseWhether to use rootFontSize when large than maxRootFontSize
      pxtoremobject
      • rootValue (Default is the same as rootFontSize)
      • unitPrecision: 5
      • propList: ['*']
      postcss-pxtorem options

      #Example

      export default {
        output: {
          convertToRem: {
            rootFontSize: 30,
            excludeEntries: ['404', 'page2'],
            pxtorem: {
              propList: ['font-size'],
            },
          },
        },
      };

      For detailed usage, please refer to rsbuild-plugin-rem.