Why do new rails 7.0.2.4 apps come with bin/dev, but rails 7.0.3 apps do not?

Viewed 835

I noticed a new Rails 7.0.2.4 app comes with a file called bin/dev, whereas a new Rails 7.0.3 app doesn't appear to come with that file.

I think running bin/dev instead of rails server precompiles javascripts on for localhost (so it is preferable to rails server when editing javascripts in development), but I don't understand why it's there for some rails versions and not others? I'm sure it would work in tandem with some other pieces of rails machinery, but I'm not sure which pieces.

(sorry, it's a basic question)

1 Answers

cssbundling-rails, jsbundling-rails, and tailwindcss-rails all add or modify bin/dev and Procfile.dev when any of the corresponding install commands are executed:

bin/rails css:install:[tailwind|bootstrap|bulma|postcss|sass]
https://github.com/rails/cssbundling-rails/blob/v1.1.0/lib/install/install.rb#L53

bin/rails javascript:install:[esbuild|rollup|webpack]
https://github.com/rails/jsbundling-rails/blob/v1.0.2/lib/install/install.rb#L44

bin/rails tailwindcss:install
https://github.com/rails/tailwindcss-rails/blob/v2.0.8/lib/install/tailwindcss.rb#L51

When running rails new there are two options that add these gems by default and execute their install command:

-j, [--javascript=JAVASCRIPT] # Choose JavaScript approach [options: importmap (default), webpack, esbuild, rollup]
                              # Default: importmap
-c, [--css=CSS]               # Choose CSS processor [options: tailwind, bootstrap, bulma, postcss, sass... check https://github.com/rails/cssbundling-rails]

-j option will add jsbundling-rails (except when importmap is specified) and will run this method:

def run_javascript
  return if options[:skip_javascript] || !bundle_install?

  case adjusted_javascript_option
  when "importmap"                    then rails_command "importmap:install"

  # NOTE: this command will add `bin/dev`
  when "webpack", "esbuild", "rollup" then rails_command "javascript:install:#{adjusted_javascript_option}"

  end
end

-c option will add tailwindcss-rails or cssbundling-rails and will run this method:

def run_css
  return if !options[:css] || !bundle_install?

  if !using_node? && options[:css] == "tailwind"

    # NOTE: this command will add `bin/dev`
    rails_command "tailwindcss:install"

  else

    # NOTE: and this command will add `bin/dev`
    rails_command "css:install:#{options[:css]}"

  end
end

If -j option is omitted rails installs importmap-rails by default and it doesn't add bin/dev when bin/rails importmap:install is executed.


Also bin/dev just runs foreman start -f Procfile.dev. foreman runs multiple commands at the same time. Take a look at Procfile.dev to see what commands are being run.

css: bin/rails tailwindcss:watch  # added by `tailwindcss-rails`

css: yarn build:css --watch       # added by `cssbundling-rails`

js: yarn build --watch            # added by `jsbundling-rails`
Related