class Jekyll::Vite::Generator

Internal: Adds all assets generated by Vite to the static_files list, so that they are copied over to the built site.

Public Instance Methods

add_static_files(site, assets_dir) click to toggle source

Internal: Add generated assets to the site's static files.

# File lib/jekyll/vite/generator.rb, line 47
def add_static_files(site, assets_dir)
  relative_assets_dir = assets_dir.relative_path_from(site.source).to_s
  vite_static_files = Dir.chdir(assets_dir.to_s) {
    Dir.glob('**/*').select { |f| File.file?(f) }
  }.map { |file|
    ViteAssetFile.new(site, site.source, relative_assets_dir, file)
  }
  site.static_files.concat(vite_static_files)
end
generate(site) click to toggle source

Internal: Set the mode based on which command was run. Builds assets with Vite only if `jekyll build` was run.

# File lib/jekyll/vite/generator.rb, line 34
def generate(site)
  serving = site.config['serving']
  ENV['JEKYLL_ENV'] ||= serving ? 'development' : 'production'
  generate_vite_build(site) unless serving
end
generate_vite_build(site) click to toggle source

Internal: Build all assets with Vite and add them to the site's static files.

# File lib/jekyll/vite/generator.rb, line 41
def generate_vite_build(site)
  ViteRuby.commands.build_from_task
  add_static_files(site, ViteRuby.config.build_output_dir)
end