An open API service indexing awesome lists of open source software.

https://github.com/coderberry/jumpstart-vite


https://github.com/coderberry/jumpstart-vite

Last synced: 10 months ago
JSON representation

Awesome Lists containing this project

README

          





Jumpstart Rails
with
Vite



License

[jumpstart]: https://github.com/excid3/jumpstart
[pro]: https://jumpstartrails.com
[vite_rails]: https://github.com/coderberry/vite_rails/tree/main/vite_rails
[esbuild]: https://github.com/evanw/esbuild
[significantly faster]: https://github.com/evanw/esbuild#why
[no bundling]: https://vitejs.dev/guide/why.html#the-problems
[bundling]: https://vitejs.dev/guide/why.html#why-bundle-for-production
[JS From Routes]: https://github.com/coderberry/js_from_routes
[vite-plugin-stimulus-hmr]: https://github.com/coderberry/vite-plugin-stimulus-hmr
[vite-plugin-full-reload]: https://github.com/coderberry/vite-plugin-full-reload

This repo is a fork of the [__Jumpstart Rails__][jumpstart] template, which is
like Laravel Spark, for Rails.

This fork replaces webpacker with [__Vite Rails__][vite_rails], and extends the
basic setup to include a working Stimulus example and Hotwire integration.

## Features ⚡️

- 💡 Instant server start
- ⚡️ Blazing fast hot reload
- 🚀 Stimulus + Turbo Hotwire
- 🛤 Path and API Helpers: [JS From Routes]
- [And more!][jumpstart]

It adds [vite-plugin-stimulus-hmr] for instant feedback on changes to
your Stimulus controllers, [vite-plugin-full-reload] to automatically
refresh the page when editing the Rails layout or templates, and __[JS From Routes]__
to automatically generate path and API helpers from the routes.

## Demo 🎥

Changes to Stimulus controllers don't require a full page refresh.


Screen Shot 2021-02-15 at 13 27 22

This feature is powered by [vite-plugin-stimulus-hmr](https://github.com/coderberry/vite-plugin-stimulus-hmr).

## Installation 💿

```bash
rails new myapp -d postgresql -m https://raw.githubusercontent.com/coderberry/jumpstart-vite/main/template.rb
```

For the rest of the instructions, head to [Jumpstart Rails][jumpstart].


## Video Comparison 🎥

Webpacker on the left, Vite on the right. I run `foreman start`, wait until the page loads, then kill the process and run it a second time.


Screen Shot 2021-02-12 at 10 03 51

### Webpacker

Installing the vanilla Jumpstart template takes 5 minutes, be prepared to watch
`node-sass` spin for a while, along with all the webpack dependencies.

jumpstart-webpacker-node-sassjumpstart-webpacker-installation

Once it's installed, and we have run `bin/rake db:create db:migrate`, we'll start it twice:


Screen Shot 2021-02-11 at 17 21 03

Cold start is particularly slow, and it locks Rails rendering.


### Vite ⚡️

Installing the Jumpstart template with Vite takes 1 minute.

jumpstart-vite-installation

Once it's installed, and we have run `bin/rake db:create db:migrate`, we'll start it twice:


Screen Shot 2021-02-11 at 17 21 25

Loads only 9 seconds after `foreman start`, and is also running a Stimulus example.

Subsequent loads are significantly faster.


## How does it work? 🤔

Vite is powered by [esbuild], which can process files [significantly faster] than Webpack.

Vite [does not bundle your code during development][no bundling], which means
as your app grows, the dev server will still start fast, and your changes will
continue be __updated instantly__.

In production, Vite [bundles your code][bundling] with tree-shaking, lazy-loading,
and common chunk splitting out of the box, to achieve optimal loading performance.


## Special Thanks 🙌

- [Jumpstart Rails][jumpstart]: 👉 Have in mind they have also built [Jumpstart Pro][pro] which also includes payments with Stripe & Braintree, team accounts, TailwindCSS, and much more.