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

logger[W]

Public Class Methods

bootstrap() click to toggle source

Internal: Refreshes the manifest.

# File lib/vite_ruby.rb, line 42
def bootstrap
  instance.manifest.refresh
end
framework_libraries() click to toggle source

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
install_tasks() click to toggle source

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
instance() click to toggle source
# File lib/vite_ruby.rb, line 37
def instance
  @instance ||= new
end
new(**config_options) click to toggle source
# File lib/vite_ruby.rb, line 69
def initialize(**config_options)
  @config_options = config_options
end
reload_with(**config_options) click to toggle source

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

builder() click to toggle source

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
commands() click to toggle source

Internal: Helper to run commands related with Vite.

# File lib/vite_ruby.rb, line 117
def commands
  @commands ||= ViteRuby::Commands.new(self)
end
config() click to toggle source

Public: Current instance configuration for Vite.

# File lib/vite_ruby.rb, line 122
def config
  @config ||= ViteRuby::Config.resolve_config(**@config_options)
end
dev_server_running?() click to toggle source

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
env() click to toggle source

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
logger() click to toggle source
# File lib/vite_ruby.rb, line 73
def logger
  @logger ||= Logger.new($stdout)
end
manifest() click to toggle source

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
run(argv, **options) click to toggle source

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
run_proxy?() click to toggle source

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