Build and publish
Configure @osdk/widget.vite-plugin, build a widget set and its manifest, deploy versions with osdk widgetset deploy, and manage them.
Publishing a widget set takes two commands: vite build produces your widget files and a manifest, and osdk widgetset deploy uploads them to Foundry as a new version. This page covers the Vite plugin, foundry.config.json, versioning, and the CLI.
Add the Vite plugin
@osdk/widget.vite-plugin writes the manifest during vite build and runs developer mode during vite. Projects from @osdk/create-widget already include it.
npm install -D @osdk/widget.vite-pluginimport foundryWidgetPlugin from "@osdk/widget.vite-plugin";
import react from "@vitejs/plugin-react";
import { defineConfig } from "vite";
export default defineConfig({
plugins: [react(), foundryWidgetPlugin()],
server: {
port: 8080,
cors: true,
},
build: {
rollupOptions: {
input: ["./index.html"],
},
},
});The plugin supports Vite 6 and 7. It takes one optional argument:
| Option | Type | Default | Description |
|---|---|---|---|
defaults.refreshHostDataOnAction | boolean | The refreshHostDataOnAction value for every widget whose config does not set it. See Config fields. |
foundryWidgetPlugin({ defaults: { refreshHostDataOnAction: true } });How the plugin finds configs
Each HTML file in build.rollupOptions.input is one widget. For each one, the plugin looks for a widget config among the modules its entry script imports:
- The file name, minus its extension, ends in
.config, such asmain.config.ts. - The file lives under
src/and the entrypoint script imports it directly. Developer mode only tracks direct imports. - The default export is the config from
defineConfig.
If you do not need the config object at runtime, a side-effect import such as import "./main.config.js"; is enough. Each entrypoint must import exactly one config.
Build multiple widgets
Add an HTML file per widget, each loading its own script that imports its own config:
Then list every HTML file as a build input. Both the array and object forms of input work:
import foundryWidgetPlugin from "@osdk/widget.vite-plugin";
import react from "@vitejs/plugin-react";
import { defineConfig } from "vite";
export default defineConfig({
plugins: [react(), foundryWidgetPlugin()],
build: {
rollupOptions: {
input: ["./index.html", "./second.html"],
},
},
});The build writes one manifest with an entry per widget, keyed by each config's id, so every widget in the set needs a different ID.
Build
npm run buildThe template's build script runs tsc && vite build. Vite writes your HTML, scripts, and styles to its output directory, dist/ by default, and the plugin then adds the manifest:
To write the manifest, the plugin reads each built HTML file for its script and stylesheet tags, evaluates each widget config in a separate Vite server, computes the version, and scans package.json dependencies for SDK packages. Parameters and events shows the result field by field.
Build errors from the plugin:
| Error | Cause |
|---|---|
foundry.config.json file not found. | No foundry.config.json in the working directory or any parent. |
No widget config files found for entrypoint ... | The entrypoint does not import a *.config module. |
Multiple widget config files found for entrypoint ... | The entrypoint's bundle includes more than one *.config module. |
No default export found in ... | The config file has no default export. |
Duplicate widget ID: ... | Two configs share an id. |
Foundry serves widget files from the root path, so Vite's base must be "/". ... | Vite's base is set to anything other than /, such as ./ or /widgets/. Remove base or set it to /. Developer mode is not affected. |
Entrypoint chunk not found for input file: ... | The built HTML's script paths do not match a bundle entry chunk, for example when an entry <script> points outside the bundle. |
Unexpected inline content found in Vite HTML output | The built HTML has an inline <script> or <link> with content. Load scripts with src. |
Unexpected ... attribute found in Vite HTML output | A <script> has attributes other than src, type, and crossorigin, or a stylesheet <link> has attributes other than rel, href, and crossorigin. |
Invalid script type attribute found in Vite HTML output: ... | A <script> type other than module or text/javascript. |
The version string ... is not SemVer compliant. | The computed version is not valid SemVer. See Versioning. |
Config validation errors, such as a widget ID that is not camelCase, are listed in Parameters and events.
foundry.config.json
The plugin and osdk widgetset commands read foundry.config.json from the working directory or the nearest parent. @osdk/create-widget writes it for you:
{
"foundryUrl": "https://example.palantirfoundry.com",
"widgetSet": {
"rid": "ri.widgetregistry..widget-set.<id>",
"directory": "./dist",
"autoVersion": {
"type": "package-json"
}
}
}| Field | Type | Default | Description |
|---|---|---|---|
foundryUrl | string | Required | Your Foundry stack. Developer mode and the CLI send requests here. |
widgetSet.rid | string | Required | The widget set RID, written to the manifest and used as the deploy target. |
widgetSet.directory | string | Required | The build output to deploy. Match Vite's build.outDir. |
widgetSet.repository | string | A code repository RID to publish through instead of the widget set. See Deploy. | |
widgetSet.autoVersion | { type: "package-json" } or { type: "git-describe", tagPrefix?: string } | package-json | How the build computes the version. |
The file is validated on load. Unknown top-level fields fail with does not match the expected schema.
Versioning
Every deployed version needs a SemVer version string. The build computes it once and writes it to the manifest's widgetSet.version; osdk widgetset deploy reads it from there and has no version flag.
The default. The version is the version field of the nearest package.json. Bump it, then rebuild before you deploy:
npm version minor
npm run buildDeploy
osdk widgetset deploy from @osdk/cli zips the build output and publishes it as a new version.
Build
npm run buildDeploy
export FOUNDRY_TOKEN=<token>
npx @osdk/cli@latest widgetset deployThe CLI reads the version from .palantir/widgets.config.json in the directory, zips everything in the directory, and uploads it. When repository is set, it uploads to that code repository on behalf of the widget set, which works only if the repository is authorized to publish the widget set. It passes the current git branch along, unless HEAD is detached or the project is not a git repository.
Every option defaults to the matching foundry.config.json field where one exists:
| Option | Default | Description |
|---|---|---|
--widgetSet | widgetSet.rid | The widget set RID. |
--foundryUrl | foundryUrl | The Foundry URL. Must start with https://. |
--directory | widgetSet.directory | The directory to upload. It must contain .palantir/widgets.config.json. |
--repository | widgetSet.repository | A code repository RID to publish through. |
--branchName | The current git branch | The branch to publish from. |
--token | A Foundry token. Conflicts with --tokenFile. | |
--tokenFile | A file containing a Foundry token. | |
--verbose, -v | Verbose logging. Repeat for more. |
Without --token or --tokenFile, the CLI reads FOUNDRY_TOKEN. The deprecated FOUNDRY_SDK_AUTH_TOKEN still works with a warning. The token must be a JWT.
After the first version is published, the widget appears in Workshop's Widget setup panel. Until then you can still preview it with developer mode.
Manage versions
The same options select the widget set and credentials:
| Command | Description |
|---|---|
osdk widgetset version list | Lists published versions, newest first, for the current git branch or --branchName. |
osdk widgetset version info <version> | Prints the details of one version as JSON. |
osdk widgetset version delete <version> | Deletes a version after a confirmation prompt. --yes or -y skips the prompt. Deletion cannot be undone. |
npx @osdk/cli@latest widgetset version list
npx @osdk/cli@latest widgetset version delete 1.3.0 --yesReact widgets
Render a widget with FoundryWidget, read typed parameters and loading states with useFoundryWidgetContext, and emit events back to the host.
Ontology as code
Define object types, links, actions, and interfaces in TypeScript with @osdk/maker, compile them to Ontology IR, and develop against them locally.