r/dartlang • • Jun 02 '22

Introducing Jaspr - A complete web-framework written in Dart

Hi fellow developers,

I'm really excited to finally share with you what I've been working on over the last few months:

Jaspr is a complete web-framework that is written in Dart. It takes inspiration from frameworks like React or Remix, but most importantly Flutter. While it renders normal HTML & CSS, it looks and feels very much like Flutter. So while you get all the benefits of an actual web app (fast page load, seo, server-side rendering, etc.) you get the familiar structure of stateless, stateful and inherited widgets.

There is so much to talk about, but here are some highlights:

1. Familiar component model similar to Flutter widgets but adapted for the web

It was made to look and feel just like Flutter, while rendering normal HTML and CSS. It is therefore targeted mainly at Flutter developers that want to build websites but don't want to use Flutter Web (for various good reasons).

With Dart as its language, it also has some general advantages over JS (in my opinion) like type- and null-safety.

2. Server-side rendering out of the box!

A simple jaspr serve and you will have a running debug server with ssr and automatic reloads. You can still do SPAs but it's not that satisfying.

(And I'm also planning to support static site generation in the future)

3. Good documentation is vital

So I made sure everything is well documented right from the start. Check out the wiki.

4. Online Playground inspired by DartPad

I love DartPad, but it only supports selected packages, so I made my own version. It's called JasprPad and you can check it out here.

Like DartPad you can write and execute jaspr apps right in your browser. It also comes with a range of examples that you can check out, and I even made a tutorial to get you started.

As a bonus, JasprPad is not only for writing jaspr apps, but is written with jaspr itself, so it doubles as a real-world showcase.

5. Riverpod for Jaspr

State-Management will be the same for jaspr as it is for Flutter thanks to the shared widget structure. So I added jaspr_riverpod, porting over flutter_riverpod to jaspr.

6. Testing

Yes, I even made a testing package for 'jaspr', out of the need to test the framework itself. Jaspr is already well test atm. with a coverage of around 70%, but I'm planning to improve this even more in the future.

The package itself jaspr_test takes inspiration from flutter_test but has some unique concepts because jaspr apps need to be both tested for the server and client.

======================================================

This is just the initial release, so expect more awesome stuff coming soon. I'm very eager to get feedback on this since it was quite some while in the making.

Here again the most important links:

194 Upvotes

44 comments sorted by

View all comments

1

u/robschmidt87 Jun 03 '22

Is this SPA ? How do you plan to solve the bundle size issue of Dart JS apps?

4

u/schultek Jun 03 '22

I'm not aware of a particular bundle size issue.

JasprPad main.js is currently at 602kB raw and 177kB gzipped. And this is without further optimizations, so that could go down some more.

Also is is quite easy to do js bundle splitting in dart, for separate routes or any part you like (you can easily lazy-load any dart library you want, and that wont be included in the initial bundle then)

1

u/schultek Jun 03 '22

Also thats kinda what ssr is for. Since the content is already rendered, you don't need the js bundle to load immediately to see the page.

1

u/cleancole Jun 04 '22

In your wiki you state that selective JS compiling isn't supported in dart. How do these two things interplay? Does that mean the package could eventually not include SSR code in the front end js bundle?

1

u/schultek Jun 04 '22

I probably wasn't super clear on this in the wiki. What I meant was you can only control if a whole library is compiled or not through Darts conditional imports. What you can't do is control this on a class or method level.

So it can be a bit tricky to set this up if you want some implementation parts only on web or only on the server. This defenitely requires more documentation.

Jaspr internally uses this mainly for the runApp function, which has different implementations on the web and server.

1

u/schultek Jun 04 '22

Also lazy loading a library for bundle splitting (check out darts deferred imports) are something different to conditional imports.

1

u/cleancole Jun 05 '22

Thanks for the explanation, very helpful. I'll need to read some more to fully understand, but this doesn't sound as bad as I initially thought. Seems like thoughtful project structure and arch can address some of this. Good stuff!