module ViteRailsLegacy::Installation

Internal: Extends the base installation script from Vite Ruby to work for a typical Rails app.

Constants

RAILS_TEMPLATES

Public Instance Methods

install_sample_files() click to toggle source

Override: Create a sample JS file and attempt to inject it in an HTML template.

# File lib/vite_rails_legacy/installation.rb, line 19
  def install_sample_files
    unless config.resolved_entrypoints_dir.join('application.js').exist?
      cp RAILS_TEMPLATES.join('entrypoints/application.js'), config.resolved_entrypoints_dir.join('application.js')
    end

    if (layout_file = root.join('app/views/layouts/application.html.erb')).exist?
      inject_line_before layout_file, '</head>', <<-HTML
    <%= vite_client_tag %>
    <%= vite_javascript_tag 'application' %>
    <!--
      If using a TypeScript entrypoint file:
        vite_typescript_tag 'application'

      If using a .jsx or .tsx entrypoint, add the extension:
        vite_javascript_tag 'application.jsx'

      Visit the guide for more information: https://vite-ruby.netlify.app/guide/rails
    -->
      HTML
    end
  end
setup_app_files() click to toggle source

Override: Setup a typical apps/web Hanami app to use Vite.

# File lib/vite_rails_legacy/installation.rb, line 11
def setup_app_files
  cp RAILS_TEMPLATES.join('config/rails-vite.json'), config.config_path
  if root.join('app/javascript').exist?
    replace_first_line config.config_path, 'app/frontend', %(    "sourceCodeDir": "app/javascript",)
  end
end