Class: ViteRuby::Config
- Inherits:
-
Object
- Object
- ViteRuby::Config
- Defined in:
- lib/vite_ruby/config.rb
Overview
Public: Allows to resolve configuration sourced from ‘config/vite.json` and environment variables, combining them with the default options.
Class Method Summary collapse
-
.resolve_config(**attrs) ⇒ Object
Public: Returns the project configuration for Vite.
Instance Method Summary collapse
-
#assets_manifest_path ⇒ Object
Internal: Path where vite-plugin-ruby outputs the assets manifest file.
-
#build_output_dir ⇒ Object
Public: The directory where Vite will store the built assets.
- #host_with_port ⇒ Object
-
#manifest_path ⇒ Object
Internal: Path where Vite outputs the manifest file.
- #protocol ⇒ Object
-
#resolved_entrypoints_dir ⇒ Object
Public: The directory where the entries are located.
-
#to_env ⇒ Object
Public: Sets additional environment variables for vite-plugin-ruby.
-
#vite_cache_dir ⇒ Object
Internal: The directory where Vite stores its processing cache.
-
#vite_root_dir ⇒ Object
Public: The directory that Vite uses as root.
-
#watched_paths ⇒ Object
Internal: Files and directories that should be watched for changes.
Class Method Details
.resolve_config(**attrs) ⇒ Object
Public: Returns the project configuration for Vite.
93 94 95 96 97 98 |
# File 'lib/vite_ruby/config.rb', line 93 def resolve_config(**attrs) config = config_defaults.merge(attrs.transform_keys(&:to_s)) file_path = File.join(config['root'], config['config_path']) file_config = config_from_file(file_path, mode: config['mode']) new DEFAULT_CONFIG.merge(file_config).merge(config_from_env).merge(config) end |
Instance Method Details
#assets_manifest_path ⇒ Object
Internal: Path where vite-plugin-ruby outputs the assets manifest file.
22 23 24 |
# File 'lib/vite_ruby/config.rb', line 22 def assets_manifest_path build_output_dir.join('manifest-assets.json') end |
#build_output_dir ⇒ Object
Public: The directory where Vite will store the built assets.
27 28 29 |
# File 'lib/vite_ruby/config.rb', line 27 def build_output_dir root.join(public_dir, public_output_dir) end |
#host_with_port ⇒ Object
12 13 14 |
# File 'lib/vite_ruby/config.rb', line 12 def host_with_port "#{ host }:#{ port }" end |
#manifest_path ⇒ Object
Internal: Path where Vite outputs the manifest file.
17 18 19 |
# File 'lib/vite_ruby/config.rb', line 17 def manifest_path build_output_dir.join('manifest.json') end |
#protocol ⇒ Object
8 9 10 |
# File 'lib/vite_ruby/config.rb', line 8 def protocol https ? 'https' : 'http' end |
#resolved_entrypoints_dir ⇒ Object
Public: The directory where the entries are located.
32 33 34 |
# File 'lib/vite_ruby/config.rb', line 32 def resolved_entrypoints_dir vite_root_dir.join(entrypoints_dir) end |
#to_env ⇒ Object
Public: Sets additional environment variables for vite-plugin-ruby.
47 48 49 50 51 52 53 |
# File 'lib/vite_ruby/config.rb', line 47 def to_env CONFIGURABLE_WITH_ENV.each_with_object({}) do |option, env| unless (value = @config[option]).nil? env["#{ ViteRuby::ENV_PREFIX }_#{ option.upcase }"] = value.to_s end end.merge(ViteRuby.env) end |
#vite_cache_dir ⇒ Object
Internal: The directory where Vite stores its processing cache.
37 38 39 |
# File 'lib/vite_ruby/config.rb', line 37 def vite_cache_dir root.join('node_modules/.vite') end |
#vite_root_dir ⇒ Object
Public: The directory that Vite uses as root.
42 43 44 |
# File 'lib/vite_ruby/config.rb', line 42 def vite_root_dir root.join(source_code_dir) end |
#watched_paths ⇒ Object
Internal: Files and directories that should be watched for changes.
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/vite_ruby/config.rb', line 56 def watched_paths [ *(watch_additional_paths + additional_entrypoints).reject { |dir| dir.start_with?('~/') || dir.start_with?(source_code_dir) }, "#{ source_code_dir }/**/*", config_path, *DEFAULT_WATCHED_PATHS, ].freeze end |