class ViteRuby
Constants
- Build
Internal: Value object with information about the last build.
- COMPANION_LIBRARIES
Internal: Companion libraries for Vite Ruby, and their target framework.
- DEFAULT_PLUGIN_VERSION
- DEFAULT_VITE_VERSION
Internal: Versions used by default when running `vite install`.
- ENV_PREFIX
Internal: Prefix used for environment variables that modify the configuration.
- VERSION
Attributes
Public Class Methods
Internal: Refreshes the manifest.
# File lib/vite_ruby.rb, line 42 def bootstrap instance.manifest.refresh end
Internal: Detects if the application has installed a framework-specific variant of Vite Ruby.
# File lib/vite_ruby.rb, line 58 def framework_libraries COMPANION_LIBRARIES.map { |name, framework| if library = Gem.loaded_specs[name] [framework, library] end }.compact end
Internal: Loads all available rake tasks.
# File lib/vite_ruby.rb, line 47 def install_tasks load File.expand_path('tasks/vite.rake', __dir__) end
# File lib/vite_ruby.rb, line 37 def instance @instance ||= new end
# File lib/vite_ruby.rb, line 69 def initialize(**config_options) @config_options = config_options end
Internal: Creates a new instance with the specified options.
# File lib/vite_ruby.rb, line 52 def reload_with(**config_options) @instance = new(**config_options) end
Public Instance Methods
Public: Keeps track of watched files and triggers builds as needed.
# File lib/vite_ruby.rb, line 112 def builder @builder ||= ViteRuby::Builder.new(self) end
Internal: Helper to run commands related with Vite.
# File lib/vite_ruby.rb, line 117 def commands @commands ||= ViteRuby::Commands.new(self) end
Public: Current instance configuration for Vite.
# File lib/vite_ruby.rb, line 122 def config @config ||= ViteRuby::Config.resolve_config(**@config_options) end
Public: Returns true if the Vite development server is currently running. NOTE: Checks only once every second since every lookup calls this method.
# File lib/vite_ruby.rb, line 79 def dev_server_running? return false unless run_proxy? return true if defined?(@running_at) && @running_at && Time.now - @running_at < 1 Socket.tcp(config.host, config.port, connect_timeout: config.dev_server_connect_timeout).close @running_at = Time.now true rescue StandardError @running_at = false end
Public: Additional environment variables to pass to Vite.
Example:
ViteRuby.env['VITE_RUBY_CONFIG_PATH'] = 'config/alternate_vite.json'
# File lib/vite_ruby.rb, line 94 def env @env ||= ENV.select { |key, _| key.start_with?(ENV_PREFIX) } end
# File lib/vite_ruby.rb, line 73 def logger @logger ||= Logger.new($stdout) end
Public: Enables looking up assets managed by Vite using name and type.
# File lib/vite_ruby.rb, line 127 def manifest @manifest ||= ViteRuby::Manifest.new(self) end
Internal: Executes the vite binary.
# File lib/vite_ruby.rb, line 107 def run(argv, **options) (@runner ||= ViteRuby::Runner.new(self)).run(argv, **options) end
Public: The proxy for assets should only run in development mode.
# File lib/vite_ruby.rb, line 99 def run_proxy? config.mode == 'development' rescue StandardError => error logger.error("Failed to check mode for Vite: #{ error.message }") false end