# 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.gem_version < Gem::Version.new('5.2.0') # 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 return unless current_vite_instance.dev_server_running? content_tag('script', '', src: current_vite_instance.manifest.prefix_vite_asset('@vite/client'), type: 'module') end # Public: Resolves the path for the specified Vite asset. # # Example: # <%= vite_asset_path 'calendar.css' %> # => "/vite/assets/calendar-1016838bab065ae1e122.css" def vite_asset_path(name, **options) path_to_asset current_vite_instance.manifest.lookup!(name, **options).fetch('file') end # Public: Renders a