Home / Function/ createServer() — vite Function Reference

createServer() — vite Function Reference

Architecture documentation for the createServer() function in server.js from the vite codebase.

Entity Profile

Dependency Diagram

graph TD
  70ec534d_270a_7efd_3bd0_0ec71061d55b["createServer()"]
  d09a3979_71cb_7043_ee68_99b1a488099a["server.js"]
  70ec534d_270a_7efd_3bd0_0ec71061d55b -->|defined in| d09a3979_71cb_7043_ee68_99b1a488099a
  style 70ec534d_270a_7efd_3bd0_0ec71061d55b fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

playground/ssr-deps/server.js lines 15–117

export async function createServer(root = process.cwd(), hmrPort) {
  const resolve = (p) => path.resolve(import.meta.dirname, p)

  const app = express()

  /**
   * @type {import('vite').ViteDevServer}
   */
  const vite = await (
    await import('vite')
  ).createServer({
    root,
    logLevel: isTest ? 'error' : 'info',
    server: {
      middlewareMode: true,
      watch: {
        // During tests we edit the files too fast and sometimes chokidar
        // misses change events, so enforce polling for consistency
        usePolling: true,
        interval: 100,
      },
      hmr: {
        port: hmrPort,
      },
    },
    appType: 'custom',
    ssr: {
      noExternal: [
        ...noExternal,
        '@vitejs/test-nested-exclude',
        '@vitejs/test-nested-include',
      ],
      external: [
        '@vitejs/test-nested-external',
        '@vitejs/test-external-entry/entry',
      ],
      optimizeDeps: {
        include: [
          ...noExternal,
          '@vitejs/test-nested-exclude > @vitejs/test-nested-include',
        ],
      },
    },
    plugins: [
      {
        name: 'dep-virtual',
        enforce: 'pre',
        resolveId(id) {
          if (id === '@vitejs/test-pkg-exports/virtual') {
            return '@vitejs/test-pkg-exports/virtual'
          }
        },
        load(id) {
          if (id === '@vitejs/test-pkg-exports/virtual') {
            return 'export default "[success]"'
          }
        },
      },
      {
        name: 'virtual-isomorphic-module',
        resolveId(id) {
          if (id === 'virtual:isomorphic-module') {
            return '\0virtual:isomorphic-module'
          }
        },
        load(id, { ssr }) {
          if (id === '\0virtual:isomorphic-module') {
            if (ssr) {
              return 'export { default } from "/src/isomorphic-module-server.js";'
            } else {
              return 'export { default } from "/src/isomorphic-module-browser.js";'
            }
          }
        },
      },
    ],
  })
  // use vite's connect instance as middleware
  app.use(vite.middlewares)

  app.use('*all', async (req, res) => {

Domain

Subdomains

Frequently Asked Questions

What does createServer() do?
createServer() is a function in the vite codebase, defined in playground/ssr-deps/server.js.
Where is createServer() defined?
createServer() is defined in playground/ssr-deps/server.js at line 15.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free