Module: ViteGdk

Defined in:
lib/vite_gdk.rb

Class Method Summary collapse

Class Method Details

.load_gdk_vite_configObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/vite_gdk.rb', line 4

def self.load_gdk_vite_config
  # can't use Rails.env.production? here because this file is required outside of Gitlab app instance
  return if ENV['RAILS_ENV'] == 'production'

  return unless File.exist?(vite_gdk_config_path)

  config = YAML.safe_load_file(vite_gdk_config_path)
  enabled = config.fetch('enabled', false)
  # ViteRuby doesn't like if env vars aren't strings
  ViteRuby.env['VITE_ENABLED'] = enabled.to_s

  return unless enabled

  # From https://vitejs.dev/config/server-options
  host = config['public_host'] || 'localhost'
  ViteRuby.env['VITE_HMR_HOST'] = host

  ViteRuby.configure(
    host: host,
    port: Integer(config['port'] || 3808),
    https: config.fetch('https', { 'enabled' => false })['enabled']
  )
end

.vite_gdk_config_pathObject



28
29
30
# File 'lib/vite_gdk.rb', line 28

def self.vite_gdk_config_path
  File.join(__dir__, '../config/vite.gdk.json')
end