[]previous and next page

default

Creates the Vite plugin that compiles a ShadowJS app's JSX and useStore calls with @shadow-js/compiler. (default of @shadow-js/vite)

Creates the Vite plugin that compiles a ShadowJS app's JSX and useStore calls with @shadow-js/compiler. Add it to the Vite config of every ShadowJS app: it runs before Vite's own TypeScript and JSX handling, so Vite never sees JSX. SSR builds get the server target. It also sets the ShadowJS JSX import source and dedupes @shadow-js/core and @shadow-js/web. A compile error is reported to Vite with its file, line and column.

Import#

ts
import shadow from "@shadow-js/vite";

Signature#

ts
function shadow(options: ShadowPluginOptions = {}): Plugin

Parameters#

Name Description
options Include and exclude filters, the runtime module, the dev, HMR and test switches, and the compiler plugins.

Returns#

A Vite plugin named shadowjs that runs with enforce: "pre".

Throws#

  • {TypeError} When include or exclude is not a RegExp, moduleName is not a non-empty string, or plugins is not a list of valid compiler plugins (a member without a unique name or a transform function, for example), naming the option. The transform hook rethrows any error that is not a CompileError, which points at a compiler bug. A CompileError goes through Vite's this.error instead, which fails the build with the file and position.

Examples#

ts
// vite.config.ts
import { shadow } from "@shadow-js/vite"; // the default export is the same function
export default { plugins: [shadow()] };