[]previous and next page

ShadowPluginOptions

Options of shadow.

Options of shadow. Every member is optional: the defaults compile a ShadowJS app for the browser in vite dev and vite build, and for the server in SSR builds.

Import#

ts
import type { ShadowPluginOptions } from "@shadow-js/vite";

Signature#

ts
interface ShadowPluginOptions {
  /**
   * Files to compile, matched against the module id without its query string. Plain `.ts` and `.js`
   * modules are compiled as well when they call `useStore`, whatever this is set to, so a
   * single-value `useStore` there takes the cell path. Files that `exclude` matches are never compiled.
   * @default /\.[cm]?[jt]sx$/ (every `.jsx` and `.tsx` file)
   * A `g` or `y` flag on the pattern is ignored: the pattern is matched from the start of every id.
   */
  include?: RegExp;
  /**
   * Files to skip. It is checked before `include`, so an excluded file is never compiled.
   * @default /[\\/]node_modules[\\/]/ (any path with a `node_modules` segment)
   */
  exclude?: RegExp;
  /**
   * Module the compiled code imports its runtime helpers from. The HMR runtime is read from
   * `<moduleName>/hmr`.
   * @default "@shadow-js/web" (`"@shadow-js/web/server"` for SSR transforms)
   */
  moduleName?: string;
  /**
   * Turn a `const` computed from reactive reads (`const double = count() * 2`) into a live value
   * inside components, so it updates without a function or `useMemo`. Set `false` to keep such
   * constants as written.
   * @default true
   */
  autoReactive?: boolean;
  /**
   * Hot-update top-level components in place during `vite dev`. It applies to the browser build
   * only: SSR transforms never get it. Test runners never hot-update modules unless this is set.
   * @default true in `vite dev`, false under a test runner
   */
  hmr?: boolean;
  /**
   * Development output: component names in the compiled code and the extra runtime checks.
   * Set `true` to get development output in a production build, or `false` to get it out of `vite dev`.
   * @default true for `vite dev` (command `serve`), false for `vite build`
   */
  dev?: boolean;
  /**
   * Run the browser build of ShadowJS under Vitest, instead of the server build that the `node`
   * condition selects. Tests that render on the server (`renderToString`) want `false`.
   * @default true when the Vitest environment is `happy-dom` or `jsdom`, otherwise false
   */
  domTests?: boolean;
  /**
   * Compiler plugins that run in the build on every module this plugin compiles: `"pre"` plugins
   * (the default) on the syntax tree before the compiler's own passes, `"post"` plugins on the
   * generated code, each group in list order. A plugin can report findings and change the module
   * (strip test attributes, collect translation keys, sort class names); it never reaches the
   * browser. Errors fail the build with the plugin's name and the position in the file; warnings go
   * to Vite's warning log. Only files that `include` matches are compiled, so a plugin sees plain
   * `.ts` modules only when `include` covers them. See `CompilerPlugin` in `@shadow-js/compiler`.
   * @default undefined (no plugins; nothing is added to the build)
   */
  plugins?: readonly CompilerPlugin[];
  /**
   * Which implementation of the compiler runs. `@shadow-js/compiler` holds three of the same compiler: a Rust addon (about ten times
   * faster on large apps), the same Rust code as WebAssembly, and the TypeScript implementation. `"auto"` uses the fastest one the
   * machine has. `"native"` requires the Rust or the WebAssembly implementation and fails, with the reason, when only TypeScript is
   * available; use it in CI to be sure builds are fast. `"javascript"` uses the TypeScript implementation only, for example to compare
   * outputs. The output is identical in every mode. A module compiled with compiler plugins is answered by the TypeScript
   * implementation in every mode. The environment variable `SHADOW_COMPILER_BACKEND` asks for one for the whole process.
   * @default "auto"
   */
  compiler?: "auto" | "javascript" | "native";
}

Members#

Name Type Description
include? include?: RegExp Files to compile, matched against the module id without its query string. Plain .ts and .js modules are compiled as well when they call useStore, whatever this is set to, so a single-value useStore there takes the cell path. Files that exclude matches are never compiled.
exclude? exclude?: RegExp Files to skip. It is checked before include, so an excluded file is never compiled.
moduleName? moduleName?: string Module the compiled code imports its runtime helpers from. The HMR runtime is read from <moduleName>/hmr.
autoReactive? autoReactive?: boolean Turn a const computed from reactive reads (const double = count() * 2) into a live value inside components, so it updates without a function or useMemo. Set false to keep such constants as written.
hmr? hmr?: boolean Hot-update top-level components in place during vite dev. It applies to the browser build only: SSR transforms never get it. Test runners never hot-update modules unless this is set.
dev? dev?: boolean Development output: component names in the compiled code and the extra runtime checks. Set true to get development output in a production build, or false to get it out of vite dev.
domTests? domTests?: boolean Run the browser build of ShadowJS under Vitest, instead of the server build that the node condition selects. Tests that render on the server (renderToString) want false.
plugins? plugins?: readonly CompilerPlugin[] Compiler plugins that run in the build on every module this plugin compiles: "pre" plugins (the default) on the syntax tree before the compiler's own passes, "post" plugins on the generated code, each group in list order. A plugin can report findings and change the module (strip test attributes, collect translation keys, sort class names); it never reaches the browser. Errors fail the build with the plugin's name and the position in the file; warnings go to Vite's warning log. Only files that include matches are compiled, so a plugin sees plain .ts modules only when include covers them. See CompilerPlugin in @shadow-js/compiler.
compiler? compiler?: "auto" | "javascript" | "native" Which implementation of the compiler runs. @shadow-js/compiler holds three of the same compiler: a Rust addon (about ten times faster on large apps), the same Rust code as WebAssembly, and the TypeScript implementation. "auto" uses the fastest one the machine has. "native" requires the Rust or the WebAssembly implementation and fails, with the reason, when only TypeScript is available; use it in CI to be sure builds are fast. "javascript" uses the TypeScript implementation only, for example to compare outputs. The output is identical in every mode. A module compiled with compiler plugins is answered by the TypeScript implementation in every mode. The environment variable SHADOW_COMPILER_BACKEND asks for one for the whole process.