Opiniated webpacker-less Rails setup with the latest Rails, using PostgreSQL, TailwindCSS, Stimulus, Hotwire and RSpec.
This comes with a full docker setup for local development including system specs that can run on M1 Apple Docker instances (and also without docker).
$ gem install dip
$ dip provision
$ dip rails s
# in another window
$ dip npm start
Without dip:
bundle install
bin/rails db:create
bin/rails db:setup SAFETY_ASSURED=1
npm install
bundle exec rails s
# in another window
npm start
You need docker
and docker-compose
installed (for MacOS just use official app).
This app uses the dip–CLI, a utility CLI tool for straightforward provisioning and interactions with applications configured by docker-compose.
To install dip, copy and run the command below. More installation options are found here: https://github.com/bibendi/dip#installation
$ gem install dip
NOTE: If needed, install the correct version of ruby locally. The current version is listed at the top of the Gemfile but should also be automatically recognized by your shell. For example, at its current version, if you're using rbenv, run: rbenv install 3.0.2
Now that we have dip installed, installing and setting up the application is just a single command:
# provision application (this will take a while)
$ dip provision
Use these commands to easily interact with the newly installed app:
# run web app with all debuging capabilities (i.e. `binding.pry`)
$ dip rails s
# run rails console
$ dip rails c
It uses StandardRB to automatically fix code style offenses.
dip standard
to automatically format the code with standard you can run:
dip standard --fix
Inside the docker container we have 2 different commands. To just run the unit tests:
$ dip rspec
and to just run the system specs:
$ dip rspec system
To use the JIT tailwind we have to run a seperate console and run:
$ dip npm start
The output will be something like this:
Creating app_rails_run ... done
> [email protected] start
> tailwindcss -i ./app/assets/stylesheets/tailwind.css -o ./app/assets/stylesheets/tailwind-build.css --watch
warn - You have enabled the JIT engine which is currently in preview.
warn - Preview features are not covered by semver, may introduce breaking changes, and can change at any time.
Rebuilding...
Done in 104ms.
Since we are using grundler (and not webpacker 🎉), we need to use the importmap provided by stimulus-rails (This is installed through the hotwire-rails gem.)
Grundler is configured to store all packages in the app/javascript/libraries
folder. This way these libraries are automaticly picked up by the importmap.
For example to use the confetti
package we can do the following:
bundle exec grundle add canvas-confetti
Then in a stimulus controller add the following:
import confetti from 'libraries/canvas-confetti'
we can now execute the confetti()
function on our stimulus controller, for example on the connect:
connect(){
confetti();
}