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
includeorexcludeis not aRegExp,moduleNameis not a non-empty string, orpluginsis not a list of valid compiler plugins (a member without a uniquenameor atransformfunction, for example), naming the option. Thetransformhook rethrows any error that is not aCompileError, which points at a compiler bug. ACompileErrorgoes through Vite'sthis.errorinstead, 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()] };