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 pagesplitRouteChunksNext pagessgByEntries

      #output.ssg

      • Type: boolean | object
      • Default Value: undefined

      Configuration to enable the application’s SSG (Static Site Generation) feature.

      Enabling SSG

      This configuration takes effect only when SSG is enabled. Please read the Static Site Generation documentation to understand how to enable SSG and its use cases.

      Recommended Reading

      The SSG feature is closely related to routing. It is recommended to understand the routing solution before using SSG.

      Info
      • Use output.ssg for single-entry apps.
      • For multi-entry apps, prefer output.ssgByEntries.
      • If output.ssg is true and output.ssgByEntries is not set, all routes under all entries are treated as SSG routes.

      #Boolean Type

      When this configuration is set to true, the SSG feature will be enabled for all entries by default. For manual routing, the root route of the entry will be rendered. For conventional routing, each route in the entry will be rendered.

      export default defineConfig({
        output: {
          ssg: true,
        },
      });

      #Object Type

      When the value type is Object, the following attributes can be configured.

      #Configuration Type

      type SSGRouteOptions =
        | string
        | {
            url: string;
            headers?: Record<string, any>;
          };
      
      type SSGOptions = {
        headers?: Record<string, any>;
        routes?: SSGRouteOptions[];
      };

      #Example

      In the example configuration below, SSG will render the pages corresponding to the /, /about, and /user/:id routes.

      For the /user/:id route, cookies will be added to the request headers.

      modern.config.ts
      export default defineConfig({
        output: {
          ssg: {
            routes: [
              '/',
              '/about',
              {
                url: '/user/modernjs',
                headers: {
                  cookies: 'name=modernjs',
                },
              },
            ],
          },
        },
      });