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 pagehostNext pagelazyCompilation

      #dev.https

      • Type: boolean | { key: string; cert: string }
      • Default: false

      After configuring this option, you can enable HTTPS Dev Server, and disabling the HTTP Dev Server.

      HTTP:

        > Local: http://localhost:8080/
        > Network: http://192.168.0.1:8080/

      HTTPS:

        > Local: https://localhost:8080/
        > Network: https://192.168.0.1:8080/

      #Automatically generate certificates

      You can directly set https to true, Modern.js will automatically generate the HTTPS certificate based on devcert.

      When using this method, you need to manually install the devcert dependency in your project:

      # npm
      npm install devcert@1.2.2 -D
      
      # yarn
      yarn add devcert@1.2.2 -D
      
      # pnpm
      pnpm add devcert@1.2.2 -D

      Then configure dev.https to true:

      export default {
        dev: {
          https: true,
        },
      };

      The devcert has some limitations, it does not currently support IP addresses yet.

      Tip

      The https proxy automatically installs the certificate and needs root authority, please enter the password according to the prompt. The password is only used to trust the certificate, and will not be leaked or be used elsewhere.

      #Manually set the certificate

      You can also manually pass in the certificate and the private key required in the dev.https option. This parameter will be directly passed to the createServer method of the https module in Node.js.

      For details, please refer to https.createServer.

      import fs from 'fs';
      
      export default {
        dev: {
          https: {
            key: fs.readFileSync('certificates/private.pem'),
            cert: fs.readFileSync('certificates/public.pem'),
          },
        },
      };

      #Clean up cert cache

      The certificate created by devcert is saved in ~/Library/Application\ Support/devcert. You may do some cleanup if needed.