Module: Opal::Vite

Defined in:
lib/opal-vite.rb,
lib/opal/vite/cli.rb,
lib/opal/vite/config.rb,
lib/opal/vite/version.rb,
lib/opal/vite/compiler.rb,
lib/opal/vite/source_map.rb,
lib/opal/vite/testing/stable_helpers.rb

Defined Under Namespace

Modules: Testing Classes: CLI, Compiler, Config, Error, SourceMapValidator

Constant Summary collapse

VERSION =
"0.2.14"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configObject



16
17
18
# File 'lib/opal-vite.rb', line 16

def config
  @config ||= Config.new
end

Class Method Details

.compile_for_vite(file_path, include_concerns: true, source_map: true) ⇒ Object

CLI entry point for compilation

Parameters:

  • file_path (String)

    The path to the Ruby file to compile

  • include_concerns (Boolean) (defaults to: true)

    Whether to include built-in concerns

  • source_map (Boolean) (defaults to: true)

    Whether to generate source maps



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/opal-vite.rb', line 34

def compile_for_vite(file_path, include_concerns: true, source_map: true)
  # Temporarily override source map setting if specified
  original_source_map = config.source_map_enabled
  config.source_map_enabled = source_map

  compiler = Compiler.new(include_concerns: include_concerns)
  result = compiler.compile_file(file_path)

  # Output JSON to stdout for the Vite plugin to consume
  puts JSON.generate(result)

  # Restore original setting
  config.source_map_enabled = original_source_map
rescue Compiler::CompilationError => e
  STDERR.puts e.message
  exit 1
end

.configure {|config| ... } ⇒ Object

Yields:



20
21
22
# File 'lib/opal-vite.rb', line 20

def configure
  yield(config) if block_given?
end

.opal_lib_pathObject

Returns the path to the opal/ directory in this gem Contains built-in concerns like StimulusHelpers



26
27
28
# File 'lib/opal-vite.rb', line 26

def opal_lib_path
  File.expand_path('../../opal', __dir__)
end