Module: Jekyll::Vite::Installation

Defined in:
lib/jekyll/vite/installation.rb

Overview

Internal: Extends the base installation script from Vite Ruby to work for a typical Jekyll site.

Constant Summary collapse

JEKYLL_TEMPLATES =
Pathname.new(File.expand_path('../../../templates', __dir__))

Instance Method Summary collapse

Instance Method Details

#helper_tagsObject



42
43
44
45
46
47
# File 'lib/jekyll/vite/installation.rb', line 42

def helper_tags
  <<-HTML.chomp("\n")
  {% vite_client_tag %}
  {% vite_javascript_tag application %}
  HTML
end

#install_sample_filesObject

Override: Inject the vite client and sample script to the default HTML template.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/jekyll/vite/installation.rb', line 24

def install_sample_files
  super
  inject_line_after_last root.join('_config.yml'), 'plugins:', '  - jekyll/vite'
  replace_first_line root.join('_config.yml'), '# exclude:', 'exclude:'
  inject_line_after_last root.join('_config.yml'), 'exclude:', <<-YML.chomp("\n")
- bin
- config
- vite.config.ts
- tmp
- Procfile.dev
  YML
  if root.join('Gemfile').read.include?('minima')
    append root.join('_includes/custom-head.html'), helper_tags
  else
    inject_line_before root.join('_layouts/default.html'), '</head>', helper_tags
  end
end

#setup_app_filesObject

Override: Setup a typical Jekyll site to use Vite.



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/jekyll/vite/installation.rb', line 11

def setup_app_files
  cp JEKYLL_TEMPLATES.join('config/jekyll-vite.json'), config.config_path
  append root.join('Procfile.dev'), 'jekyll: bin/jekyll-vite wait && bundle exec jekyll serve --livereload'
  cp JEKYLL_TEMPLATES.join('exe/dev'), root.join('exe/dev')
  `bundle binstub jekyll-vite --path #{ root.join('bin') }`
  `bundle config --delete bin`
  append root.join('Rakefile'), <<~RAKE
    require 'jekyll/vite'
    ViteRuby.install_tasks
  RAKE
end