Home / Function/ createBundleRunner() — vue Function Reference

createBundleRunner() — vue Function Reference

Architecture documentation for the createBundleRunner() function in create-bundle-runner.ts from the vue codebase.

Entity Profile

Dependency Diagram

graph TD
  6a9fa059_9fc3_cee8_cd4d_4e2ad5f3f96e["createBundleRunner()"]
  e99f1014_4151_d755_aee1_9fb410ccbf8a["create-bundle-runner.ts"]
  6a9fa059_9fc3_cee8_cd4d_4e2ad5f3f96e -->|defined in| e99f1014_4151_d755_aee1_9fb410ccbf8a
  209f4be6_e015_fc89_c153_21caf40c00af["createBundleRendererCreator()"]
  209f4be6_e015_fc89_c153_21caf40c00af -->|calls| 6a9fa059_9fc3_cee8_cd4d_4e2ad5f3f96e
  708af6a4_c04f_a7d6_fee2_6bfcaaf9aea3["compileModule()"]
  6a9fa059_9fc3_cee8_cd4d_4e2ad5f3f96e -->|calls| 708af6a4_c04f_a7d6_fee2_6bfcaaf9aea3
  2fa07d30_80b5_9681_25e1_2ba7f1b44d6f["createSandbox()"]
  6a9fa059_9fc3_cee8_cd4d_4e2ad5f3f96e -->|calls| 2fa07d30_80b5_9681_25e1_2ba7f1b44d6f
  1e8183a7_6227_1a09_7d70_4fa55ca24ab1["deepClone()"]
  6a9fa059_9fc3_cee8_cd4d_4e2ad5f3f96e -->|calls| 1e8183a7_6227_1a09_7d70_4fa55ca24ab1
  style 6a9fa059_9fc3_cee8_cd4d_4e2ad5f3f96e fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/server-renderer/src/bundle-renderer/create-bundle-runner.ts lines 93–158

export function createBundleRunner(entry, files, basedir, runInNewContext) {
  const evaluate = compileModule(files, basedir, runInNewContext)
  if (runInNewContext !== false && runInNewContext !== 'once') {
    // new context mode: creates a fresh context and re-evaluate the bundle
    // on each render. Ensures entire application state is fresh for each
    // render, but incurs extra evaluation cost.
    return (userContext = {}) =>
      new Promise(resolve => {
        // @ts-expect-error
        userContext._registeredComponents = new Set()
        const res = evaluate(entry, createSandbox(userContext))
        resolve(typeof res === 'function' ? res(userContext) : res)
      })
  } else {
    // direct mode: instead of re-evaluating the whole bundle on
    // each render, it simply calls the exported function. This avoids the
    // module evaluation costs but requires the source code to be structured
    // slightly differently.
    let runner // lazy creation so that errors can be caught by user
    let initialContext
    return (userContext = {}) =>
      new Promise(resolve => {
        if (!runner) {
          const sandbox = runInNewContext === 'once' ? createSandbox() : global
          // the initial context is only used for collecting possible non-component
          // styles injected by vue-style-loader.
          // @ts-expect-error
          initialContext = sandbox.__VUE_SSR_CONTEXT__ = {}
          runner = evaluate(entry, sandbox)
          // On subsequent renders, __VUE_SSR_CONTEXT__ will not be available
          // to prevent cross-request pollution.
          // @ts-expect-error
          delete sandbox.__VUE_SSR_CONTEXT__
          if (typeof runner !== 'function') {
            throw new Error(
              'bundle export should be a function when using ' +
                '{ runInNewContext: false }.'
            )
          }
        }
        // @ts-expect-error
        userContext._registeredComponents = new Set()

        // vue-style-loader styles imported outside of component lifecycle hooks
        if (initialContext._styles) {
          // @ts-expect-error
          userContext._styles = deepClone(initialContext._styles)
          // #6353 ensure "styles" is exposed even if no styles are injected
          // in component lifecycles.
          // the renderStyles fn is exposed by vue-style-loader >= 3.0.3
          const renderStyles = initialContext._renderStyles
          if (renderStyles) {
            Object.defineProperty(userContext, 'styles', {
              enumerable: true,
              get() {
                // @ts-expect-error
                return renderStyles(userContext._styles)
              }
            })
          }
        }

        resolve(runner(userContext))
      })
  }
}

Subdomains

Frequently Asked Questions

What does createBundleRunner() do?
createBundleRunner() is a function in the vue codebase, defined in packages/server-renderer/src/bundle-renderer/create-bundle-runner.ts.
Where is createBundleRunner() defined?
createBundleRunner() is defined in packages/server-renderer/src/bundle-renderer/create-bundle-runner.ts at line 93.
What does createBundleRunner() call?
createBundleRunner() calls 3 function(s): compileModule, createSandbox, deepClone.
What calls createBundleRunner()?
createBundleRunner() is called by 1 function(s): createBundleRendererCreator.

Analyze Your Own Codebase

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

Try Supermodel Free