Class: Lilac::CLI::BundleAssetWriter

Inherits:
Object
  • Object
show all
Defined in:
lib/lilac/cli/build/bundle_asset_writer.rb

Overview

In :bundle delivery mode, emits all components' default templates, named templates, and Ruby scripts into a single dist/lilac.bundle.html. Pages reference it via <link rel="lilac-bundle">, and PageCompiler's boot module / the runtime registry fetches it before mount.

For the :compiled target, scripts are NOT inlined into the bundle (the compiled wasm has no parser to evaluate text/ruby). Instead they are aggregated and compiled into a single bundle.mrb, plus a tiny standalone start_only.mrb (just Lilac.start) — both filenames ride on the returned BundleAssets so PageCompiler can chain them into each page's boot module.

See decisions §20.6 (Lilac.start placement) and the bundle-fetch proposal for the rationale behind splitting bundle.mrb / start_only.mrb instead of appending Lilac.start to the bundle.

Defined Under Namespace

Classes: BundleAssets

Constant Summary collapse

BUNDLE_FILENAME =
'lilac.bundle.html'
BUNDLE_URL =
"/#{BUNDLE_FILENAME}"

Instance Method Summary collapse

Constructor Details

#initialize(components:, template_cache:, target:, output_dir:, bytecode_builder:) ⇒ BundleAssetWriter

Returns a new instance of BundleAssetWriter.



36
37
38
39
40
41
42
43
# File 'lib/lilac/cli/build/bundle_asset_writer.rb', line 36

def initialize(components:, template_cache:, target:,
               output_dir:, bytecode_builder:)
  @components = components
  @template_cache = template_cache
  @target = target
  @output_dir = output_dir
  @bytecode_builder = bytecode_builder
end

Instance Method Details

#write!Object

Writes the bundle file and (for :compiled) compiles bundle.mrb + start_only.mrb. Returns a BundleAssets, or nil when there are no components to bundle.



48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/lilac/cli/build/bundle_asset_writer.rb', line 48

def write!
  return nil if @components.empty?

  parts, compiled_scripts = assemble_parts
  write_html_file!(parts)
  bundle_mrb, start_only_mrb = compile_compiled_scripts!(compiled_scripts)

  BundleAssets.new(
    url: BUNDLE_URL,
    bundle_mrb: bundle_mrb,
    start_only_mrb: start_only_mrb
  )
end