logo
  • 指南
  • 配置
  • 插件
  • API
  • 示例
  • 社区
  • Modern.js 2.x 文档
  • 简体中文
    • 简体中文
    • English
    • 配置使用
      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
      介绍
      plugins
      router
      performance
      buildCache
      bundleAnalyze
      chunkSplit
      dnsPrefetch
      preconnect
      prefetch
      preload
      printFileSize
      profile
      removeConsole
      removeMomentLocale
      experiments
      sourceBuild
      builderPlugins
      📝 编辑此页面
      上一页setupMiddlewares下一页watchFiles

      #dev.startUrl

      • 类型: boolean | string | string[] | undefined
      • 默认值: undefined

      dev.startUrl 用于设置 Dev Server 启动时自动在浏览器中打开的页面 URL。

      默认情况下,Dev Server 启动时不会打开任何页面。

      你可以设置为如下的值:

      export default {
        dev: {
          // 打开项目的默认页面,等价于 `http://localhost:<port>`
          startUrl: true,
          // 打开指定的页面
          startUrl: 'http://localhost:8080',
          // 打开多个页面
          startUrl: ['http://localhost:8080', 'http://localhost:8080/about'],
        },
      };

      #端口号占位符

      由于端口号可能会发生变动,你可以使用 <port> 占位符来指代当前端口号,Modern.js 会自动将占位符替换为实际监听的端口号。

      export default {
        dev: {
          startUrl: 'http://localhost:<port>/home',
        },
      };

      #打开指定浏览器

      在 MacOS 上,通过设置环境变量 BROWSER,你可以指定 Dev Server 在启动时打开的浏览器,支持如下的值:

      • Google Chrome Canary
      • Google Chrome Dev
      • Google Chrome Beta
      • Google Chrome
      • Microsoft Edge
      • Brave Browser
      • Vivaldi
      • Chromium

      建议设置在.env.local文件中。