Class: ViteRuby::CLI::SSR

Inherits:
Vite
  • Object
show all
Defined in:
lib/vite_ruby/cli/ssr.rb

Constant Summary collapse

DEFAULT_ENV =
CURRENT_ENV || 'production'
JS_EXTENSIONS =
%w[js mjs cjs]

Constants inherited from Vite

Vite::CURRENT_ENV

Instance Method Summary collapse

Methods inherited from Vite

executable_options, shared_options

Instance Method Details

#call(mode:, inspect: false, trace_deprecation: false) ⇒ Object

Raises:

  • (ArgumentError)


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/vite_ruby/cli/ssr.rb', line 10

def call(mode:, inspect: false, trace_deprecation: false)
  ViteRuby.env['VITE_RUBY_MODE'] = mode

  ssr_entrypoint = JS_EXTENSIONS
    .map { |ext| ViteRuby.config.ssr_output_dir.join("ssr.#{ ext }") }
    .find(&:exist?)

  raise ArgumentError, "No ssr entrypoint found `#{ ViteRuby.config.ssr_output_dir.relative_path_from(ViteRuby.config.root) }/ssr.{#{ JS_EXTENSIONS.join(',') }}`. Have you run bin/vite build --ssr?" unless ssr_entrypoint

  cmd = [
    'node',
    ('--inspect-brk' if inspect),
    ('--trace-deprecation' if trace_deprecation),
    ssr_entrypoint,
  ]
  Kernel.exec(*cmd.compact.map(&:to_s))
end