module Esbuilder

Constants

VERSION

Public Class Methods

build_entry_point(entry_point) click to toggle source
# File lib/esbuilder.rb, line 13
def build_entry_point(entry_point)
  outdir = Engine.config.output_path
  options = build_options_for(entry_point)
  result = Esbuild.build(**options)
  result.metafile.outputs.each_key.map { |key| "/#{Rails.root.join(key).relative_path_from(outdir)}" }
end
entry_point_to_outputs(entry_point) click to toggle source
# File lib/esbuilder.rb, line 7
def entry_point_to_outputs(entry_point)
  return outputs_from_manifest(entry_point) if Engine.config.use_manifest

  build_entry_point(entry_point)
end

Private Class Methods

build_options_for(entry_point) click to toggle source
# File lib/esbuilder.rb, line 33
def build_options_for(entry_point)
  global_options = Engine.config.build_config&.fetch(:global, nil)
  specific_options = Engine.config.build_config&.fetch(:entry_points, nil)&.fetch(entry_point.to_sym, nil)

  assets = Engine.config.base_path
  outdir = Engine.config.output_path
  entry_point_file = assets.join(entry_point).to_s
  options = {
    outbase: assets.to_s,
    entry_points: [entry_point_file],
    entry_names: "[dir]/[name]-[hash]",
    write: true,
    bundle: true,
    outdir: outdir,
    public_path: "/",
    metafile: true,
    abs_working_dir: Rails.root.to_s,
  }
  options.deep_merge! global_options.deep_symbolize_keys if global_options.present?
  options.deep_merge! specific_options.deep_symbolize_keys if specific_options.present?
  options
end
manifest() click to toggle source
# File lib/esbuilder.rb, line 29
def manifest
  @manifest ||= JSON.parse(File.read(Engine.config.manifest_path))
end
outputs_from_manifest(entry_point) click to toggle source
# File lib/esbuilder.rb, line 22
def outputs_from_manifest(entry_point)
  unless (outputs = manifest[entry_point])
    raise UnknownEntryPointError, "Unknown entry point #{entry_point}"
  end
  outputs
end