Getting started
Your first project
From an empty folder to a styled Jaspr page, step by step. About ten minutes, with the Dart SDK already installed.
1. Create the Jaspr app
Install the Jaspr CLI once, then create a project and open it:
dart pub global activate jaspr_cli
jaspr create my_site
cd my_site
2. Add jx_cli
Add the package, then generate jx.yaml. It is commented and works as is: it scans
lib and web
and writes web/jx.css.
dart pub add jx_cli
dart run jx_cli:jx init
3. Link the stylesheet
Jaspr serves the web
folder at the root of the site, so web/jx.css
is available at /jx.css. Reference it in the
Document of lib/main.server.dart:
Document(
title: 'My site',
head: [
link(rel: 'stylesheet', href: '/jx.css'),
],
body: App(),
)
4. Write a component
Classes go in the classes
string of any Jaspr element. Write them in full: the CLI reads string literals.
import 'package:jaspr/dom.dart';
import 'package:jaspr/jaspr.dart';
import 'package:jx_cli/ui.dart';
class Welcome extends StatelessComponent {
const Welcome({super.key});
@override
Component build(BuildContext context) {
return section(classes: 'mw:[40rem] mx:auto p:6 md:p:10', [
h1(classes: 'fs:3xl md:fs:5xl fw:extrabold c:gray-900', [.text('Hello JX')]),
p(classes: 'mt:4 fs:lg c:gray-700', [.text('Styled with JX CSS.')]),
div(classes: 'mt:6', [
JxButton(onClick: () {}, [.text('Get started')]),
]),
]);
}
}
Using JX Components
Components such as JxButton
bring their own classes. Add packages: [jx_cli/ui]
to jx.yaml so the CLI scans them too.
5. Build and serve
Run the watcher in one terminal and the Jaspr dev server in another:
dart run jx_cli:jx build -w
jaspr serve
Edit a class and save: the stylesheet is rebuilt and the page picks it up on reload. To skip the second terminal, enable the builder described in Automatic builds.
Next steps
- Learn how a class reads in Class syntax, then the conditions in Variants.
- Make the layout adapt to the screen with Responsive design.
-
Give the project its own colors and fonts in the Theme Studio, then paste the result in
jx.yaml. -
Before deploying, build a minified stylesheet with
jx build -m.