Cell API
    Preparing search index...

    Class CellPlugin

    Turns the component graph into the DI container and configuration of each target and builds the client environment (frontend → <outDir>/public) and the server environment (backend, one file → <outDir>/server). Exposed to Vite through cell.

    Index
    command: "build" | "serve" = 'build'
    coreDir: string
    format: "esm" | "cjs"
    model: ProjectModel
    options: CellPluginOptions = {}
    output: OutputWriter
    polyfills: NodePolyfills
    root: string
    REQUIRE_SHIM: RegExp = ...

    The line scripts/build-esm.ts adds to ESM files of Cell packages that call require.

    • get componentNames(): string[]

      Components of the project other than itself.

      Returns string[]

    • get single(): boolean

      --single with a frontend and a backend: the frontend goes into the server bundle.

      Returns boolean

    • Builds the targets of the project (the frontend first, as a single server embeds it), then writes the files around the bundles.

      Parameters

      • builder: ViteBuilder

      Returns Promise<void>

    • Parameters

      • userConfig: UserConfig
      • env: ConfigEnv

      Returns UserConfig

    • cell dev: the client environment serves the frontend with HMR, the server environment runs the backend in a module runner. Cell packages go through the plugin in both (they must see the generated container and configuration, and share one @celljs/core); other dependencies stay in node_modules: pre-bundled for the browser, loaded by Node for the server.

      Parameters

      • nodeEnv: string

      Returns UserConfig

    • A file of the public directory that is copied, not built (favicon, component assets); see OutputWriter.frontendFile.

      Parameters

      • path: string

      Returns string | undefined

    • Parameters

      • id: string
      • path: string

      Returns boolean

    • Parameters

      • ctx: ResolveContext
      • environment: string
      • id: string

      Returns Promise<string | null>

    • The page of the frontend: the project's index.html or the built-in one, with the frontend configuration applied.

      Returns string

    • Parameters

      • ctx: ResolveContext
      • environment: string
      • id: string
      • Optionalimporter: string

      Returns string | Promise<{ id: string } | null> | null

    • Parameters

      • ctx: ResolveContext
      • target: Target
      • refs: ModuleRef[]

      Returns Promise<string[]>

    • CommonJS dependencies inlined into an ES module bundle still reference the free __dirname and __filename; point them at the bundle file, as a CommonJS bundle would.

      Parameters

      • nodeEnv: string

      Returns Record<string, string>

    • CommonJS files of the project (generated clients like prisma's) cannot run as ES modules in the module runner of cell dev. Node loads them instead, in the same process, and the module re-exports what they export.

      Parameters

      • id: string

      Returns string | null

    • How the server bundle refers to its own location: import.meta on Node.js; fixed paths under /bundle on workerd, which leaves import.meta.url undefined (createRequire then throws).

      Parameters

      • runtime: ServerRuntime = 'node'

      Returns { dirname: string; filename: string; url: string }

    • CommonJS libraries bundled into the ESM server expect what a CommonJS server gives them: a require in scope (prisma loads its engine with eval('require')) and require.main (app-root-path, used by typeorm, reads require.main.filename). Expose the bundle's __require as require, with the bundle itself as the main module.

      Parameters

      • code: string
      • runtime: ServerRuntime = 'node'

      Returns string | null

    • import.meta.dirname / filename exist from Node.js 20.11; the Node.js of FC (20.10) and SCF (18) lack them, so the bundle sets them from import.meta.url when they are missing.

      Parameters

      • code: string

      Returns string

    • Cell packages built as ES modules keep node-only require('x') calls working in Node through a local const require = createRequire(import.meta.url). The bundler cannot see through that local binding, so the required packages would stay outside the bundle and be missing next to it. Drop the shim in the bundle: require('x') is then bundled like any other dependency.

      Parameters

      • code: string

      Returns string | null

    • The module runner of cell dev evaluates sources as ES modules, which have no require; the bundler of cell build accepts require('x') next to import. Give TypeScript and JavaScript sources outside node_modules that call require( a module-local one, as the ESM builds of Cell packages have.

      Parameters

      • code: string
      • id: string

      Returns string | null