The chat responses are generated using Generative AI technology for intuitive search and may not be entirely accurate. They are not intended as professional advice. For full details, including our use rights, privacy practices and potential export control restrictions, please refer to our Generative AI Service Privacy Information. As this is a test version, please let us know if something irritating comes up. Like you get recommended a chocolate fudge ice cream instead of an energy managing application. If that occurs, please use the feedback button in our contact form!
Skip to content

Set up the project

2612

This guide describes the layout used by all examples in this documentation. It is a plain Vite project with a manifest.json and a packaging script added. Any other toolchain works as long as the output is a static site with relative URLs.

Single-view application

  • hello-polarion/
    • manifest.json application identity and views
    • package.json
    • vite.config.ts base './'
    • tsconfig.json
    • index.html Vite entry page
    • src/
      • main.tsx
      • App.tsx
      • styles.css
      • polarion.ts small REST / endpoint helper (optional)
      • types.ts REST response shapes (optional)
    • server-scripts/ optional
      • …
    • scripts/
      • package.mjs builds the ZIP
    • public/ files copied as-is into the view (icons)

package.json

package.json
{
  "name": "hello-polarion",
  "private": true,
  "version": "0.1.0",
  "type": "module",
  "scripts": {
    "dev": "vite",
    "build": "tsc -b && vite build",
    "package": "npm run build && node scripts/package.mjs",
    "preview": "vite preview"
  },
  "dependencies": {
    "polarion-app-sdk": "file:../_sdk/polarion-app-sdk-0.5.2-preview.tgz",
    "react": "^19.2.0",
    "react-dom": "^19.2.0"
  },
  "devDependencies": {
    "@types/node": "^24.10.1",
    "@types/react": "^19.2.5",
    "@types/react-dom": "^19.2.3",
    "@vitejs/plugin-react": "^5.1.1",
    "adm-zip": "^0.5.16",
    "typescript": "~5.9.3",
    "vite": "^7.2.4"
  }
}

Notes:

  • polarion-app-sdk is installed from a tarball. The examples vendor the file under examples/_sdk/ and reference it with file:; a project of your own would normally use the URL of your server (see Install the SDK).
  • adm-zip is only needed by the packaging script.
  • npm run package builds first, then zips.

tsconfig.json

tsconfig.json
{
  "compilerOptions": {
    "target": "ES2022",
    "lib": ["ES2022", "DOM", "DOM.Iterable"],
    "module": "ESNext",
    "moduleResolution": "bundler",
    "jsx": "react-jsx",
    "types": ["vite/client"],
    "strict": true,
    "noEmit": true,
    "skipLibCheck": true,
    "verbatimModuleSyntax": true,
    "allowImportingTsExtensions": true
  },
  "include": ["src"]
}

moduleResolution: "bundler" is what lets TypeScript find the SDK's type definitions through the exports field of its package.json.

vite.config.ts

vite.config.ts
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';

export default defineConfig({
  plugins: [react()],
  base: './',
});

base: './' is mandatory. Polarion serves the view under /polarion/apps/<identifier>/<rootDirectory>/, and Vite's default absolute /assets/… URLs would point at the Polarion root.

The packaging script

The script in scripts/package.mjs reads manifest.json, stages <identifier>/manifest.json, copies dist/ to <identifier>/<rootDirectory>/ and server-scripts/ if present, and writes <identifier>.zip. It is deliberately small so that you can read and adapt it; see the full listing in Your first application.

Applications with several views

Each view needs its own folder in the package with its own index.html. Two approaches work well.

Keep one sub-folder per view, each a complete Vite project, and a top-level manifest.json:

  • inspector/
    • manifest.json
    • card/ Vite project for the form extension
      • package.json
      • src/
    • sidebar/ Vite project for the sidebar
      • package.json
      • src/
    • server-scripts/
    • scripts/
      • package.mjs builds every view, assembles the ZIP

Simple to understand, and each view can use different libraries. Shared code lives in a third folder that both import with a relative path, or in a local npm workspace.

One package.json, one src/ with a folder per view, and a build script that runs Vite once per view with a mode:

vite.config.ts
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import { resolve } from 'node:path';

const VIEWS = ['card', 'sidebar'] as const;

export default defineConfig(({ mode }) => {
  const view = (VIEWS as readonly string[]).includes(mode) ? mode : VIEWS[0];
  return {
    plugins: [react()],
    base: './',
    root: resolve(__dirname, 'src', view),       // src/card/index.html, src/sidebar/index.html
    build: { outDir: resolve(__dirname, 'dist', view), emptyOutDir: true },
  };
});
package.json (scripts)
"scripts": {
  "build": "tsc -b && vite build --mode card && vite build --mode sidebar",
  "package": "npm run build && node scripts/package.mjs"
}

The packaging script then copies dist/<view>/ to <identifier>/<view>/ for every view in the manifest. Shared components live in src/shared/. The reference application tsapp-1 uses a variant of this layout.

Avoid Vite's multi-page mode with a shared dist/assets/ folder: the shared assets would sit outside every rootDirectory, and only files inside view folders are guaranteed to be served.

Icons and other static files

Put icons in public/; Vite copies them unchanged to the root of dist/, which becomes the root of the view folder. Reference them in the manifest by file name ("menuIcon": "icon16.png").

Linting and formatting

Nothing Polarion-specific. The reference application uses ESLint with typescript-eslint and the React hooks plugin; the examples here keep the toolchain minimal.

Source control

Commit manifest.json, the sources, package.json and package-lock.json. Ignore node_modules/, dist/, the staging folder and the generated ZIP:

.gitignore
node_modules
dist
package
*.zip