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
  26b57d84_121f_755e_f3cd_eb5e57e71799["createBundleRunner()"]
  14f9202e_1e3d_a247_6325_f9f31fa8ab03["createBundleRendererCreator()"]
  14f9202e_1e3d_a247_6325_f9f31fa8ab03 -->|calls| 26b57d84_121f_755e_f3cd_eb5e57e71799
  8bd7e049_f7e6_4cb7_120c_2d629d66deb9["compileModule()"]
  26b57d84_121f_755e_f3cd_eb5e57e71799 -->|calls| 8bd7e049_f7e6_4cb7_120c_2d629d66deb9
  673bb0ac_774b_0ff0_3bd8_c886a2909e07["createSandbox()"]
  26b57d84_121f_755e_f3cd_eb5e57e71799 -->|calls| 673bb0ac_774b_0ff0_3bd8_c886a2909e07
  a7d1d86a_e0ba_f6a5_2461_4eb104d5483f["deepClone()"]
  26b57d84_121f_755e_f3cd_eb5e57e71799 -->|calls| a7d1d86a_e0ba_f6a5_2461_4eb104d5483f
  style 26b57d84_121f_755e_f3cd_eb5e57e71799 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.
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