lib/vite_ruby.rb in vite_ruby-1.2.15 vs lib/vite_ruby.rb in vite_ruby-1.2.16
- old
+ new
@@ -33,52 +33,32 @@
}
class << self
extend Forwardable
- def_delegators :instance, :config, :commands, :run_proxy?
+ def_delegators :instance, :config, :commands, :env, :run, :run_proxy?
def_delegators :config, :mode
def instance
- @instance ||= ViteRuby.new
+ @instance ||= new
end
- # Public: Additional environment variables to pass to Vite.
- #
- # Example:
- # ViteRuby.env['VITE_RUBY_CONFIG_PATH'] = 'config/alternate_vite.json'
- def env
- @env ||= load_env_variables
- end
-
# Internal: Refreshes the manifest.
def bootstrap
instance.manifest.refresh
end
# Internal: Loads all available rake tasks.
def install_tasks
load File.expand_path('tasks/vite.rake', __dir__)
end
- # Internal: Executes the vite binary.
- def run(argv, **options)
- ViteRuby::Runner.new(instance).run(argv, **options)
+ # Internal: Creates a new instance with the specified options.
+ def reload_with(**config_options)
+ @instance = new(**config_options)
end
- # Internal: Refreshes the config after setting the env vars.
- def reload_with(env_vars)
- env.update(env_vars)
- @instance = nil
- config
- end
-
- # Internal: Allows to obtain any env variables for configuration options.
- def load_env_variables
- ENV.select { |key, _| key.start_with?(ENV_PREFIX) }
- end
-
# Internal: Detects if the application has installed a framework-specific
# variant of Vite Ruby.
def framework_libraries
COMPANION_LIBRARIES.map { |name, framework|
if library = Gem.loaded_specs[name]
@@ -88,10 +68,14 @@
end
end
attr_writer :logger
+ def initialize(**config_options)
+ @config_options = config_options
+ end
+
def logger
@logger ||= Logger.new($stdout)
end
# Public: Returns true if the Vite development server is currently running.
@@ -105,18 +89,31 @@
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'
+ def env
+ @env ||= ENV.select { |key, _| key.start_with?(ENV_PREFIX) }
+ end
+
# Public: The proxy for assets should only run in development mode.
def run_proxy?
config.mode == 'development'
rescue StandardError => error
logger.error("Failed to check mode for Vite: #{ error.message }")
false
end
+ # Internal: Executes the vite binary.
+ def run(argv, **options)
+ (@runner ||= ViteRuby::Runner.new(self)).run(argv, **options)
+ end
+
# Public: Keeps track of watched files and triggers builds as needed.
def builder
@builder ||= ViteRuby::Builder.new(self)
end
@@ -125,10 +122,10 @@
@commands ||= ViteRuby::Commands.new(self)
end
# Public: Current instance configuration for Vite.
def config
- @config ||= ViteRuby::Config.resolve_config
+ @config ||= ViteRuby::Config.resolve_config(**@config_options)
end
# Public: Enables looking up assets managed by Vite using name and type.
def manifest
@manifest ||= ViteRuby::Manifest.new(self)