Introduction • How to use • Download • References • Related • License
Svelte is one of the lightfull frontend layers you can use. In this example we use Svelte to render some data provided by Rust actix server
Example
# Clone this repository
$ git clone https://github.com/ricardodarocha/rust-svelte-dashboard.git
# Go into the repository
$ cd rust-svelte-dashboard/api/ #to run api
$ cd rust-svelte-dashboard/dash/ #to run frontend
# Open with VSCode
$ code .
# I suggest you open two terminal windows
# install and run the server
cd api/
cargo check
cargo run
# install and run the client
cd dash/
npm install
npm run dev
Dash will run at port 3000 Api will run at port 3001
Choose some kpi
GET http://localhost/api/metricas/ALFA/30 GET http://localhost/api/metricas/GAMA/30
let alfa = [{"label":"1", "value", 39.0},{"label":"2", "value", 39.0},...,{"label":"30", "value", 37.0}]
let beta = [{"label":"1", "value", 199.0},{"label":"2", "value", 179.0},...,{"label":"30", "value", 201.0}]
🚧 soon
No binary yet
npm install --save svelte-tiny-linked-charts
//app.svelte
<script>
import { LinkedChart, LinkedLabel, LinkedValue } from "svelte-tiny-linked-charts"
</script>
<div class="wrapper">
<LinkedChart { data } />
</div>
If you want to use Vite in other projects, just try this preset
npm init vite@latest
√ Project name: ... new-dash
√ Select a framework: » svelte
√ Select a variant: » svelte
Scaffolding project in .\new-dash
Done. Now run:
cd new-dash
npm install
npm run dev
Why use this over SvelteKit?
vite dev
and vite build
wouldn't work in a SvelteKit environment, for example.This template contains as little as possible to get started with Vite + Svelte, while taking into account the developer experience with regards to HMR and intellisense. It demonstrates capabilities on par with the other create-vite
templates and is a good starting point for beginners dipping their toes into a Vite + Svelte project.
Should you later need the extended capabilities and extensibility provided by SvelteKit, the template has been structured similarly to SvelteKit so that it is easy to migrate.
Why global.d.ts
instead of compilerOptions.types
inside jsconfig.json
or tsconfig.json
?
Setting compilerOptions.types
shuts out all other types not explicitly listed in the configuration. Using triple-slash references keeps the default TypeScript setting of accepting type information from the entire workspace, while also adding svelte
and vite/client
type information.
Why include .vscode/extensions.json
?
Other templates indirectly recommend extensions via the README, but this file allows VS Code to prompt the user to install the recommended extension upon opening the project.
Why enable checkJs
in the JS template?
It is likely that most cases of changing variable types in runtime are likely to be accidental, rather than deliberate. This provides advanced typechecking out of the box. Should you like to take advantage of the dynamically-typed nature of JavaScript, it is trivial to change the configuration.
Why is HMR not preserving my local component state?
HMR state preservation comes with a number of gotchas! It has been disabled by default in both svelte-hmr
and @sveltejs/vite-plugin-svelte
due to its often surprising behavior. You can read the details here.
If you have state that's important to retain within a component, consider creating an external store which would not be replaced by HMR.
// store.js
// An extremely simple external store
import { writable } from 'svelte/store'
export default writable(0)
This software uses Svelte
This software uses svelte-tiny-linked-charts
This software was powered with Vite
web components basic java script dashboard svelte tiny linked charts see references vite see references
Rust - A linguagem mais querida 🦀
Linkedin ricardo-da-rocha-vitor Site ricardodarocha.com.br · GitHub @ricardodarocha · Twitter @ricardorochadev
GNU