Class: Jekyll::Vite::Generator
- Inherits:
-
Generator
- Object
- Generator
- Jekyll::Vite::Generator
- Defined in:
- lib/jekyll/vite/generator.rb
Overview
Internal: Adds all assets generated by Vite to the static_files list, so that they are copied over to the built site.
Defined Under Namespace
Classes: ViteAssetFile
Instance Method Summary collapse
-
#add_static_files(site, assets_dir) ⇒ Object
Internal: Add generated assets to the site’s static files.
-
#generate(site) ⇒ Object
Internal: Set the mode based on which command was run.
-
#generate_vite_build(site) ⇒ Object
Internal: Build all assets with Vite and add them to the site’s static files.
Instance Method Details
#add_static_files(site, assets_dir) ⇒ Object
Internal: Add generated assets to the site’s static files.
47 48 49 50 51 52 53 54 55 |
# 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) ⇒ Object
Internal: Set the mode based on which command was run. Builds assets with Vite only if ‘jekyll build` was run.
34 35 36 37 38 |
# 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) ⇒ Object
Internal: Build all assets with Vite and add them to the site’s static files.
41 42 43 44 |
# 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 |