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 pagesourceBuild

      #builderPlugins

      • Type: RsbuildPlugin[]
      • Default: []

      Used to configure the Rsbuild plugin.

      Rsbuild is the build tool of Modern.js, please read Build Engine for background. If you want to know how to write Rsbuild plugins, you can refer to Rsbuild - Plugin System.

      #Precautions

      This option is used to configure the Rsbuild plugins. If you need to configure other types of plugins, please select the corresponding configs:

      • Use plugins to configure Modern.js framework plugins.
      • Use tools.bundlerChain to configure Rspack or webpack plugins.
      • Use tools.babel to configure Babel plugins.

      #When to use

      In most scenarios, we recommend you to use the Modern.js framework plugin, which can be registered through the plugins config. Because the API provided by the framework plugin is richer and more capable, while the API provided by the Rsbuild plugin can only be used to build scenes.

      When you need to reference some existing Rsbuild plugins (and there is no related capability in Modern.js), or reuse Rsbuild plugins between different frameworks, you can use the builderPlugins field to register them.

      #Example

      Below is an example of using the Rsbuild plugin.

      #Using plugins on npm

      To use a plugin on npm, you need to install the plugin through the package manager and import it.

      modern.config.ts
      import myRsbuildPlugin from 'my-rsbuild-plugin';
      
      export default defineConfig({
        builderPlugins: [myRsbuildPlugin()],
      });

      #Using local plugins

      Use the plugin in the local code repository, you can import it directly through the relative path import.

      modern.config.ts
      import myRsbuildPlugin from './plugin/myRsbuildPlugin';
      
      export default defineConfig({
        builderPlugins: [myRsbuildPlugin()],
      });

      #Plugin configuration options

      If the plugin provides some custom configuration options, you can pass in the configuration through the parameters of the plugin function.

      modern.config.ts
      import myRsbuildPlugin from 'my-rsbuild-plugin';
      
      export default defineConfig({
        builderPlugins: [
          myRsbuildPlugin({
            foo: 1,
            bar: 2,
          }),
        ],
      });