TypeScript / JavaScript
On this page
Get Started with vivi and TypeScript
This guide will help you to get started to use vivi with TypeScript and JavaScript. Slint itself works with different TypeScript / JavaScript toolchains. For this guide we will focus on bun, node and deno.
1. Install a Toolchain
Install your preferred toolchain and follow the instructions in this guide that are related to the corresponding toolchain.
Install bun
Install instructions for bun can be found here.
Install node
Install instructions for node can be found here.
Install deno
Install instructions for deno can be found here.
2. Generating a new project
Generating a new project with bun
Create a new directory called hello-vivi navigate inside of it an execute the following command:
bun initGenerating a new project with node
Navigate to desired directory and execute the following command:
npm init hello-vivi
To use TypeScript with node the following additional steps are needed:
Install Typescript tools by executing the following command:
npm install --save-dev typescript
After it is finished add a file called tsconfig.json to your project and with the following content:
{
"compilerOptions": {
"module": "commonjs",
"esModuleInterop": true,
"target": "es6",
"moduleResolution": "node",
"sourceMap": true,
"outDir": "dist"
},
"lib": ["es2015"]
}
Add a file called index.ts to your project.
Generating a new project with deno
Navigate to desired directory and execute the following command:
deno init hello-vivi3. Add Slint to your project
First you need to add Slint as dependency to your project.
Add Slint using bun
Executing the following command:
bun install slint-uiAdd Slint using node
Executing the following command:
npm install slint-uiAdd Slint using deno
Create a new file called deno.json with the following content:
{
"imports": {
"slint-ui": "npm:slint-ui"
}
}4. Add a Slint file to your project
Add a new file to your project with name index.slint and add the following content to the file:
import { MagicWindow, FilledButton } from "@vivi/magic.slint";
export component AppWindow inherits MagicWindow {
preferred-width: 600px;
preferred-height: 400px;
title: "Hello vivi";
FilledButton {
text: "Click me";
}
}5. Clone the vivi repository
Actual it is need to clone the vivi repository to use its Slint components for a TypeScript / JavaScript project.
Navigate to a directory where you want to store vivi and run the following command:
git clone https://codeberg.org/vivi-ui/vivi.git6. Update content of index.ts
Replace the content of index.ts of your project with the following content:
import * as slint from "slint-ui";
const ui = slint.loadFile(
new URL("index.slint", import.meta.url),
{
libraryPaths: { "vivi": "../path/to/vivi/vivi/ui" }
}
) as any;
const appWindow = new ui.AppWindow();
await appWindow.run();
Replace ../path/to/ with the path where you have cloned in the vivi repository.
7. Start the application
Start with bun
Execute the following command:
bun run index.tsStart with node
Execute the following commands:
npx tsc index.ts
node dist/index.jsStart with deno
Execute the following command:
deno run index.ts