[]previous and next page

CompileOptions

Options of compile.

Options of compile.

Import#

ts
import type { CompileOptions } from "@shadow-js/compiler";

Signature#

ts
interface CompileOptions {
  /**
   * Name of the module being compiled. Its extension selects the parser language (`.tsx`, `.ts`,
   * `.mts`, `.cts`; anything else, including `.jsx` and `.js`, parses as JSX), and the name is used as
   * the `id` of a {@link CompileError} and as the source of the source map.
   * @default "module.tsx"
   */
  filename?: string;
  /**
   * Output flavor: `"dom"` emits template cloning and reactive bindings, `"ssr"` emits strings
   * with hydration keys.
   * @default "dom"
   */
  generate?: Target;
  /**
   * Module the generated code imports its runtime helpers from. The `dom` output then imports from
   * it (and the `hmr` output from `<moduleName>/hmr`).
   * @default "@shadow-js/web" for the dom target, "@shadow-js/web/server" for the ssr target
   */
  moduleName?: string;
  /**
   * Development output. On the `dom` target, component calls also pass the component's name as a
   * third argument, so devtools can label it. It does not enable HMR and has no effect on the
   * `ssr` target.
   * @default false
   */
  dev?: boolean;
  /**
   * Forgiving reactivity: inside a component, a `const` computed from reactive reads stays live
   * wherever it is used, without a function or a `useMemo`. Set `false` to leave such constants as
   * written. It does not affect the `useStore` rewrite, which always runs.
   * @default true
   */
  autoReactive?: boolean;
  /**
   * Wrap the top-level components of the module so an edit swaps them in place; a module that
   * exports only components also accepts hot updates itself (`import.meta.hot`). Applies to the `dom` target only; it is
   * ignored for `ssr`, and it does not depend on {@link CompileOptions.dev}: callers such as
   * `@shadow-js/vite` pass it only in development.
   * @default false
   */
  hmr?: boolean;
  /**
   * `ssr` target only: mark each template root with a hydration key so the browser can attach to
   * the server markup. Set `false` for markup that is never hydrated.
   * @default true
   */
  hydratable?: boolean;
  /**
   * Produce a source map in {@link CompileResult.map}. When `false`, `map` is `null`.
   * @default true
   */
  sourceMap?: boolean;
  /**
   * Compiler plugins. They run in the build, on one module at a time: `"pre"` plugins (the default)
   * on the syntax tree of the source before every compiler pass, `"post"` plugins on the tree of
   * the generated code, each group in list order. A plugin reports findings and changes the module
   * through edits; its errors are {@link CompileError}s that carry the plugin's name. See
   * {@link CompilerPlugin}. An absent or empty list costs nothing.
   * @default undefined (no plugins)
   */
  plugins?: readonly CompilerPlugin[];
}

Members#

Name Type Description
filename? filename?: string Name of the module being compiled. Its extension selects the parser language (.tsx, .ts, .mts, .cts; anything else, including .jsx and .js, parses as JSX), and the name is used as the id of a CompileError and as the source of the source map.
generate? generate?: Target Output flavor: "dom" emits template cloning and reactive bindings, "ssr" emits strings with hydration keys.
moduleName? moduleName?: string Module the generated code imports its runtime helpers from. The dom output then imports from it (and the hmr output from <moduleName>/hmr).
dev? dev?: boolean Development output. On the dom target, component calls also pass the component's name as a third argument, so devtools can label it. It does not enable HMR and has no effect on the ssr target.
autoReactive? autoReactive?: boolean Forgiving reactivity: inside a component, a const computed from reactive reads stays live wherever it is used, without a function or a useMemo. Set false to leave such constants as written. It does not affect the useStore rewrite, which always runs.
hmr? hmr?: boolean Wrap the top-level components of the module so an edit swaps them in place; a module that exports only components also accepts hot updates itself (import.meta.hot). Applies to the dom target only; it is ignored for ssr, and it does not depend on CompileOptions.dev: callers such as @shadow-js/vite pass it only in development.
hydratable? hydratable?: boolean ssr target only: mark each template root with a hydration key so the browser can attach to the server markup. Set false for markup that is never hydrated.
sourceMap? sourceMap?: boolean Produce a source map in CompileResult.map. When false, map is null.
plugins? plugins?: readonly CompilerPlugin[] Compiler plugins. They run in the build, on one module at a time: "pre" plugins (the default) on the syntax tree of the source before every compiler pass, "post" plugins on the tree of the generated code, each group in list order. A plugin reports findings and changes the module through edits; its errors are CompileErrors that carry the plugin's name. See CompilerPlugin. An absent or empty list costs nothing.