# frozen_string_literal: true # Public: Allows to render HTML tags for scripts and styles processed by Vite. module ViteRails::Helper DEFAULT_VITE_SKIP_PRELOAD_TAGS = Rails::VERSION::MAJOR <= 5 && Rails::VERSION::MINOR < 2 # Public: Returns the current Vite Rails instance. def current_vite_instance ViteRails.instance end # Public: Renders a script tag for vite/client to enable HMR in development. def vite_client_tag content_tag('script', '', src: '/@vite/client', type: 'module') if ViteRails.dev_server_running? end # Public: Computes the relative path for the specified given Vite asset. # # Example: # <%= vite_asset_path 'calendar.css' %> # => "/vite/assets/calendar-1016838bab065ae1e122.css" def vite_asset_path(name, **options) current_vite_instance.manifest.lookup!(name, **options).fetch('file') end # Public: Renders a