Skip to content

1. First Web App (Vite)

NotElementImport edited this page Nov 10, 2024 · 5 revisions

To create your first application, it is better to use vite. Fast build under prod, and support for typescript during development

Creating project Vite

We'll use the vanilla-ts template

npm create vite@latest horizon-app -- --template vanilla-ts

Go to the directory

cd horizon-app

Install dependencies

npm i;
npm i horizon-core

Prepare project

Go to src/main.ts and edit file

import { defineApp, render } from "horizon-core";
import { comp } from "horizon-core/component";
import { useSignal } from "horizon-core/state";

const app = defineApp()

const mainComponent = comp((_, { text, $ }) => {
    const counter = useSignal(
        0, { asRaw: value => `Counter: ${value}` }
    )

    $('button', {
        '@click': () => counter.value++
    }, () => {
        text(counter)
    })
})

mainComponent.composable.dom = document.body.querySelector('#app') 
    ?? document.body

render(app, mainComponent)

Launch Dev

npm run dev

Launch Prod

npm run build;
npm run preview

see also Creating component

Clone this wiki locally