inertiajs / inertia-rails

The Rails adapter for Inertia.js.
https://inertia-rails.dev/
MIT License
568 stars 44 forks source link

When creating a new Rails 8.0 app with `rails new`, what is the best practice? #159

Closed jbwl closed 1 day ago

jbwl commented 2 days ago

Hello, first of all thank you for this wonderful gem.

I think it would be helpful to include the installation instructions for a brand new Rails app (8.0 or 7.2), especially what options / flags to use for the rails new command in order to be able to use inertia-rails with Kamal 2, Propshaft, esbuild and Tailwind.

Specifically, I am wondering if I need to specify Tailwind with rails new because the inertia-rails generator also installs Tailwind. Then, will inertia-js work with esbuild? And Propshaft (the new default)? And in turn, the Dockerfile that is created along the Rails app, will I be able to deploy with Kamal?

The relevant rails new flags in question are:

# Choose JavaScript approach
# Default: importmap
# Possible values: importmap, bun, webpack, esbuild, rollup
-j, --js,      [--javascript=JAVASCRIPT] 

# or do I have to skip Javascript completely?
-J  # Skip JavaScript files

# Choose CSS processor. Check https://github.com/rails/cssbundling-rails for more options
# Possible values: tailwind, bootstrap, bulma, postcss, sass
-c,            [--css=CSS] 

# Skip Kamal setup (because it might not be compatible with inertia-rails anyway?)
[--skip-kamal]                                                

# Asset pipeline - do I need to skip it?
-A   # Indicates when to generate skip asset pipeline

TLDR; what options do I have to choose when doing rails new with Rails 8.0 when I want to use inertiajs, but also be able to use Rails 8 goodies like Kamal and Propshaft and esbuild?

Thank you!

skryukov commented 2 days ago

Hey, @jbwl, thanks for the issue!

Kamal 2, Propshaft, esbuild and Tailwind.

I don't think we're going to support esbuild since it's more complicated than using vite-ruby.

Personally I use this command to setup a new app:

rails new -JA myapp # maybe it's better to only use -J and leave Propshaft in place
cd myapp
bundle add inertia-rails_contrib # until generators are upstreamed
bin/rails g inertia:install

Right now that won't add Kamal 2 configs, but I plan to add Kamal 2 support to the install generator in the near future.

In short, Kamal 2 config for Inertia Rails is just a copy of the one generated by rails new -j esbuild, but with an updated asset_path to /rails/public.

jbwl commented 2 days ago

Thank you, very clear answer! I will try to make Kamal work with your advice.