jekyll-vite 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +14 -0
- data/LICENSE.txt +21 -0
- data/README.md +130 -0
- data/lib/jekyll/vite.rb +16 -0
- data/lib/jekyll/vite/config.rb +15 -0
- data/lib/jekyll/vite/generator.rb +38 -0
- data/lib/jekyll/vite/installation.rb +30 -0
- data/lib/jekyll/vite/proxy.rb +51 -0
- data/lib/jekyll/vite/tags.rb +154 -0
- data/lib/jekyll/vite/version.rb +7 -0
- data/templates/config/jekyll-vite.json +15 -0
- metadata +110 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7db450fb50d7d77214596d9f5a78518b4618c2100118502e2d4178cdd242e0ad
|
4
|
+
data.tar.gz: 74dc9598aa9b76bc755c4c1d0513fb6d9ebc50c22c738768e31280146b469d6d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: '09b2ee91572039d136a1db1b3aa4f0cc4f21bd4560a1d5d37d8d548a3176fa4c72b04b479e7f857e7aca2d8e4fec91dd70dce16086635ad905b1488a4ec9173a'
|
7
|
+
data.tar.gz: a6ed6af1378fb9bd128ab45f5f0eea48db46a8dc4f38bdde58f17e1515f894473e451cfc29aa323b470faf137ccbd786106b5d4530f84507cd0c285a43dece8a
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
## 0.0.1 (2021-07-02)
|
2
|
+
|
3
|
+
### Features
|
4
|
+
|
5
|
+
* Build vite assets when generating site and preserve assets correctly ([0b9a138](https://github.com/ElMassimo/vite_ruby/commit/0b9a138393a00c96119e42d5a59ac71539d00912))
|
6
|
+
* Ignore Vite dir when the dev server is active, add the last build ([548a47f](https://github.com/ElMassimo/vite_ruby/commit/548a47f8bbb6f22820083d22d4628d445149ba46))
|
7
|
+
* Implement a WEBrick proxy servlet for Jekyll ([b5afe03](https://github.com/ElMassimo/vite_ruby/commit/b5afe03b763235c23d9eaf940086d6ddb19399dc))
|
8
|
+
* Implement liquid tags to render script and stylesheet tags ([4cbb679](https://github.com/ElMassimo/vite_ruby/commit/4cbb679af2625f31954c56b7cda032c896d7e127))
|
9
|
+
* Read mode from JEKYLL_ENV ([acd7181](https://github.com/ElMassimo/vite_ruby/commit/acd7181c507cd1971f056462f240dec0071acf3b))
|
10
|
+
* Serve files from the cache when the Vite dev server is down ([d695718](https://github.com/ElMassimo/vite_ruby/commit/d695718b1805211aa8b63c81d140b7212d2347f5))
|
11
|
+
* Track dependencies on entrypoints ([5b8c413](https://github.com/ElMassimo/vite_ruby/commit/5b8c41336085e24568750bcbc77192f498488f46))
|
12
|
+
|
13
|
+
|
14
|
+
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Maximo Mussini
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
<h1 align="center">
|
2
|
+
<a href="https://vite-ruby.netlify.app/">
|
3
|
+
<img src="https://raw.githubusercontent.com/ElMassimo/vite_ruby/main/docs/public/logo.svg" width="120px"/>
|
4
|
+
</a>
|
5
|
+
|
6
|
+
<br>
|
7
|
+
|
8
|
+
<a href="https://vite-ruby.netlify.app/">
|
9
|
+
Jekyll ➕ Vite.js
|
10
|
+
</a>
|
11
|
+
|
12
|
+
<br>
|
13
|
+
|
14
|
+
<p align="center">
|
15
|
+
<!-- <a href="https://github.com/ElMassimo/jekyll-vite/actions">
|
16
|
+
<img alt="Build Status" src="https://github.com/ElMassimo/jekyll-vite/workflows/build/badge.svg"/>
|
17
|
+
</a> -->
|
18
|
+
<!-- <a href="https://codeclimate.com/github/ElMassimo/jekyll-vite">
|
19
|
+
<img alt="Maintainability" src="https://codeclimate.com/github/ElMassimo/jekyll-vite/badges/gpa.svg"/>
|
20
|
+
</a>
|
21
|
+
<a href="https://codeclimate.com/github/ElMassimo/jekyll-vite">
|
22
|
+
<img alt="Test Coverage" src="https://codeclimate.com/github/ElMassimo/jekyll-vite/badges/coverage.svg"/> -->
|
23
|
+
</a>
|
24
|
+
<a href="https://rubygems.org/gems/jekyll-vite">
|
25
|
+
<img alt="Gem Version" src="https://img.shields.io/gem/v/jekyll-vite.svg?colorB=e9573f"/>
|
26
|
+
</a>
|
27
|
+
<a href="https://github.com/ElMassimo/jekyll-vite/blob/master/LICENSE.txt">
|
28
|
+
<img alt="License" src="https://img.shields.io/badge/license-MIT-428F7E.svg"/>
|
29
|
+
</a>
|
30
|
+
</p>
|
31
|
+
</h1>
|
32
|
+
|
33
|
+
[website]: https://github.com/ElMassimo/vite-ruby
|
34
|
+
[website]: https://vite-ruby.netlify.app/
|
35
|
+
[jekyll]: https://jekyllrb.com/
|
36
|
+
[configuration reference]: https://vite-ruby.netlify.app/config/
|
37
|
+
[features]: https://vite-ruby.netlify.app/guide/introduction.html
|
38
|
+
[guides]: https://vite-ruby.netlify.app/guide/
|
39
|
+
[config]: https://vite-ruby.netlify.app/config/
|
40
|
+
[vite.js]: http://vitejs.dev/
|
41
|
+
[Issues]: https://github.com/ElMassimo/jekyll-vite/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc
|
42
|
+
[Discussions]: https://github.com/ElMassimo/jekyll-vite/discussions
|
43
|
+
[no bundling]: https://vitejs.dev/guide/why.html#the-problems
|
44
|
+
[bundling]: https://vitejs.dev/guide/why.html#why-bundle-for-production
|
45
|
+
[rollup.js]: https://rollupjs.org
|
46
|
+
[esbuild]: https://esbuild.github.io/
|
47
|
+
|
48
|
+
Use [Vite.js] in [Jekyll] and enjoy a modern assets pipeline! ⚡️
|
49
|
+
|
50
|
+
<small>_This integration is powered by [__Vite Ruby__][Vite Ruby]_.</small>
|
51
|
+
|
52
|
+
## Features ⚡️
|
53
|
+
|
54
|
+
- ⚡️ Blazing fast hot reload
|
55
|
+
- 📦 Zero-config builds
|
56
|
+
- 🎨 Use your favorite languages/preprocessors/utilities (TypeScript, Tailwind CSS, etc.)
|
57
|
+
|
58
|
+
## Why Vite? 🤔
|
59
|
+
|
60
|
+
[Jekyll] does not have an extensible asset pipeline, which limits the amount of
|
61
|
+
integrations that exist for different languages and preprocessors. By default,
|
62
|
+
assets are not fingerprinted which is problematic for caching.
|
63
|
+
|
64
|
+
[Vite.js] has an extensible architecture and is built on top of [rollup.js], and as
|
65
|
+
a result there is an active ecosystem of plugins and tooling available. In addition,
|
66
|
+
it's [no bundling] design provides a very fluid authoring experience—changes to
|
67
|
+
your assets are reflected instantly in your browser.
|
68
|
+
|
69
|
+
## Installation 💿
|
70
|
+
|
71
|
+
Add this line to your site's Gemfile:
|
72
|
+
|
73
|
+
```ruby
|
74
|
+
gem 'jekyll-vite'
|
75
|
+
```
|
76
|
+
|
77
|
+
Then, run:
|
78
|
+
|
79
|
+
```bash
|
80
|
+
bundle install
|
81
|
+
bundle exec vite install
|
82
|
+
```
|
83
|
+
|
84
|
+
This will install the plugin in `_config.yml`, and generate a sample setup in
|
85
|
+
`_layouts/default.html` (if it exists).
|
86
|
+
|
87
|
+
```yml
|
88
|
+
plugins:
|
89
|
+
- jekyll/vite
|
90
|
+
```
|
91
|
+
|
92
|
+
```html
|
93
|
+
<head>
|
94
|
+
<!-- meta tags, etc -->
|
95
|
+
{% vite_client_tag %}
|
96
|
+
{% vite_javascript_tag application %}
|
97
|
+
{% vite_stylesheet_tag styles.scss %}
|
98
|
+
</head>
|
99
|
+
```
|
100
|
+
|
101
|
+
Additional installation instructions are available in the [documentation website][website].
|
102
|
+
|
103
|
+
## Getting Started 💻
|
104
|
+
|
105
|
+
Run <kbd>bin/vite dev</kbd> to start the Vite development server, and then
|
106
|
+
restart your Jekyll server with <kbd>bin/jekyll serve</kbd>.
|
107
|
+
|
108
|
+
Visit any page and you should see a printed console output: `Vite ⚡️ Ruby`.
|
109
|
+
|
110
|
+
For more [guides] and a full [configuration reference], check the [documentation website][website].
|
111
|
+
|
112
|
+
_A new section for Jekyll is coming soon!_
|
113
|
+
|
114
|
+
## Contact ✉️
|
115
|
+
|
116
|
+
Please use [Issues] to report bugs you find, and [Discussions] to make feature requests or get help.
|
117
|
+
|
118
|
+
Don't hesitate to _⭐️ star the project_ if you find it useful!
|
119
|
+
|
120
|
+
Using it in your site? Always love to hear about it! 😃
|
121
|
+
|
122
|
+
## Acknowledgements
|
123
|
+
|
124
|
+
- [Jekyll] — Even after all this time, it's still a great static site generator.
|
125
|
+
- [Vite.js] — Frontend tooling with a focus on the developer experience.
|
126
|
+
|
127
|
+
## License
|
128
|
+
|
129
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
130
|
+
|
data/lib/jekyll/vite.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'jekyll'
|
4
|
+
require 'vite_ruby'
|
5
|
+
|
6
|
+
require 'jekyll/vite/version'
|
7
|
+
require 'jekyll/vite/config'
|
8
|
+
require 'jekyll/vite/tags'
|
9
|
+
require 'jekyll/vite/generator'
|
10
|
+
require 'jekyll/vite/proxy'
|
11
|
+
|
12
|
+
Jekyll::Hooks.register(:site, :after_init) do |site|
|
13
|
+
if site.config['serving'] && ViteRuby.instance.dev_server_running?
|
14
|
+
site.config['exclude'] << ViteRuby.config.source_code_dir
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jekyll::Vite::Config
|
4
|
+
# Override: Provide default values for a typical Jekyll site.
|
5
|
+
def config_defaults(**opts)
|
6
|
+
require 'jekyll'
|
7
|
+
config = Jekyll.configuration
|
8
|
+
super(**opts, mode: Jekyll.env).tap do |defaults|
|
9
|
+
defaults['public_dir'] = config['cache_dir']
|
10
|
+
defaults['build_cache_dir'] = File.join(config['cache_dir'], 'vite-build')
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
ViteRuby::Config.singleton_class.prepend(Jekyll::Vite::Config)
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Internal: Adds all assets generated by Vite to the static_files list, so
|
4
|
+
# that they are copied over to the built site.
|
5
|
+
class Jekyll::Vite::Generator < Jekyll::Generator
|
6
|
+
safe true
|
7
|
+
priority :highest
|
8
|
+
|
9
|
+
class ViteAssetFile < Jekyll::StaticFile
|
10
|
+
# Override: Copy to the configured public_output_dir
|
11
|
+
def cleaned_relative_path
|
12
|
+
super.sub(
|
13
|
+
ViteRuby.config.build_output_dir.relative_path_from(@site.source).to_s,
|
14
|
+
ViteRuby.config.public_output_dir,
|
15
|
+
)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# Internal: Set the mode based on which command was run.
|
20
|
+
# Builds assets with Vite only if `jekyll build` was run.
|
21
|
+
def generate(site)
|
22
|
+
serving = site.config['serving']
|
23
|
+
ENV['JEKYLL_ENV'] ||= serving ? 'development' : 'production'
|
24
|
+
generate_vite_build(site) unless serving
|
25
|
+
end
|
26
|
+
|
27
|
+
# Internal: Build all assets with Vite and add them to the site's static files.
|
28
|
+
def generate_vite_build(site)
|
29
|
+
ViteRuby.commands.build_from_task
|
30
|
+
assets_dir = ViteRuby.config.build_output_dir.relative_path_from(site.source)
|
31
|
+
files = Dir.chdir(ViteRuby.config.build_output_dir.to_s) {
|
32
|
+
Dir.glob('**/*').select { |f| File.file?(f) }
|
33
|
+
}
|
34
|
+
site.static_files.concat(files.map { |file|
|
35
|
+
ViteAssetFile.new(site, site.source, assets_dir, file)
|
36
|
+
})
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'jekyll/vite'
|
4
|
+
|
5
|
+
# Internal: Extends the base installation script from Vite Ruby to work for a
|
6
|
+
# typical Jekyll site.
|
7
|
+
module Jekyll::Vite::Installation
|
8
|
+
JEKYLL_TEMPLATES = Pathname.new(File.expand_path('../../../templates', __dir__))
|
9
|
+
|
10
|
+
# Override: Setup a typical Jekyll site to use Vite.
|
11
|
+
def setup_app_files
|
12
|
+
cp JEKYLL_TEMPLATES.join('config/jekyll-vite.json'), config.config_path
|
13
|
+
append root.join('Rakefile'), <<~RAKE
|
14
|
+
require 'jekyll/vite'
|
15
|
+
ViteRuby.install_tasks
|
16
|
+
RAKE
|
17
|
+
end
|
18
|
+
|
19
|
+
# Override: Inject the vite client and sample script to the default HTML template.
|
20
|
+
def install_sample_files
|
21
|
+
super
|
22
|
+
inject_line_after root.join('_config.yml'), 'plugins:', ' - jekyll/vite'
|
23
|
+
inject_line_before root.join('_layouts/default.html'), '</head>', <<-HTML.chomp("\n")
|
24
|
+
{% vite_client_tag %}
|
25
|
+
{% vite_javascript_tag application %}
|
26
|
+
HTML
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
ViteRuby::CLI::Install.prepend(Jekyll::Vite::Installation)
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rack'
|
4
|
+
require 'webrick'
|
5
|
+
require 'jekyll/commands/serve/servlet'
|
6
|
+
|
7
|
+
# Internal: Extend the default servlet to add a Rack-based proxy in order to
|
8
|
+
# forward asset requests to the Vite.js development server.
|
9
|
+
module Jekyll::Vite::Proxy
|
10
|
+
# Internal: Used to detect proxied requests since it's not a valid status code.
|
11
|
+
STATUS_SERVE_ORIGINAL = 0o07
|
12
|
+
|
13
|
+
def initialize(server, *args)
|
14
|
+
@server = server
|
15
|
+
super
|
16
|
+
end
|
17
|
+
|
18
|
+
# Override: Serve compiled Vite assets from the temporary folder as needed.
|
19
|
+
def set_filename(req, res)
|
20
|
+
original_root = @root.dup
|
21
|
+
if req.path_info.start_with?("/#{ ViteRuby.config.public_output_dir }/")
|
22
|
+
@root = ViteRuby.config.root.join(ViteRuby.config.public_dir)
|
23
|
+
end
|
24
|
+
super.tap { @root = original_root }
|
25
|
+
end
|
26
|
+
|
27
|
+
# Override: Detect the special status set by the Proxy Servlet and use the
|
28
|
+
# default Jekyll response instead.
|
29
|
+
def service(req, res)
|
30
|
+
proxy_servlet.service(req, res)
|
31
|
+
super if res.status == STATUS_SERVE_ORIGINAL
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
# Internal: A WEBRick servlet that uses a Rack proxy internally.
|
37
|
+
def proxy_servlet
|
38
|
+
@proxy_servlet ||= begin
|
39
|
+
# Called by the proxy if a request shouldn't be served by Vite.
|
40
|
+
app = ->(_env) { [STATUS_SERVE_ORIGINAL, {}, []] }
|
41
|
+
|
42
|
+
# Initialize the proxy which is a Rack app.
|
43
|
+
proxy = ViteRuby::DevServerProxy.new(app)
|
44
|
+
|
45
|
+
# Return a servlet compliant with WEBrick.
|
46
|
+
Rack::Handler::WEBrick.new(@server, proxy)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
Jekyll::Commands::Serve::Servlet.prepend Jekyll::Vite::Proxy
|
@@ -0,0 +1,154 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Internal: Base class for all tags.
|
4
|
+
class Jekyll::Vite::Tag < Jekyll::Tags::IncludeTag
|
5
|
+
include Jekyll::Filters::URLFilters
|
6
|
+
|
7
|
+
# Override: Set the context to make the site available in the URLFilters.
|
8
|
+
def render(context)
|
9
|
+
@context = context
|
10
|
+
@params = @params.is_a?(String) ? parse_params(context).transform_keys(&:to_sym) : @params || {}
|
11
|
+
if @file = render_variable(@file)
|
12
|
+
validate_file_name(@file)
|
13
|
+
track_file_dependency(@file)
|
14
|
+
end
|
15
|
+
block_given? ? yield : raise(NotImplementedError, "Implement render in #{ self.class.name }")
|
16
|
+
end
|
17
|
+
|
18
|
+
# Override: Modified version that can resolve recursive references.
|
19
|
+
def render_variable(variable)
|
20
|
+
variable = Liquid::Template.parse(variable).render!(@context) while VARIABLE_SYNTAX =~ variable
|
21
|
+
variable
|
22
|
+
end
|
23
|
+
|
24
|
+
protected
|
25
|
+
|
26
|
+
# Internal: Resolves the path for the specified Vite asset.
|
27
|
+
def vite_asset_path(name, **options)
|
28
|
+
vite_manifest.path_for(name, **options)
|
29
|
+
end
|
30
|
+
|
31
|
+
# Internal: Returns the current manifest loaded by Vite Ruby.
|
32
|
+
def vite_manifest
|
33
|
+
ViteRuby.instance.manifest
|
34
|
+
end
|
35
|
+
|
36
|
+
# Internal: Renders HTML attributes inside a tag.
|
37
|
+
def stringify_attrs(**attrs)
|
38
|
+
attrs.map { |key, value| %(#{ key }="#{ value }") }.join(' ')
|
39
|
+
end
|
40
|
+
|
41
|
+
# Internal: Renders an HTML tag of the specified type.
|
42
|
+
def tag(type, **attrs)
|
43
|
+
self_closing = type != :script
|
44
|
+
%i[href src].each { |key| attrs[key] = relative_url(attrs[key]) if attrs.key?(key) }
|
45
|
+
["<#{ type } ", stringify_attrs(**attrs), self_closing ? '/>' : "></#{ type }>"].join
|
46
|
+
end
|
47
|
+
|
48
|
+
# Internal: Renders HTML link tags.
|
49
|
+
def link_tags(sources, **attrs)
|
50
|
+
sources.map { |href| tag(:link, href: href, **attrs) }.join("\n")
|
51
|
+
end
|
52
|
+
|
53
|
+
# Internal: Renders HTML script tags.
|
54
|
+
def script_tags(sources, **attrs)
|
55
|
+
sources.map { |src| tag(:script, src: src, **attrs) }.join("\n")
|
56
|
+
end
|
57
|
+
|
58
|
+
# Internal: Adds entrypoint files managed by Vite as a dependency in the
|
59
|
+
# renegerator in order to support --incremental mode.
|
60
|
+
def track_file_dependency(name)
|
61
|
+
site = @context.registers[:site]
|
62
|
+
path = site.in_source_dir(File.join(ViteRuby.config.source_code_dir, ViteRuby.config.entrypoints_dir, name))
|
63
|
+
|
64
|
+
['', '.css', '.js', '.ts'].each do |ext|
|
65
|
+
if File.file?(asset_path = "#{ path }#{ ext }")
|
66
|
+
return [asset_path, last_build_metadata_path].each do |filename|
|
67
|
+
add_include_to_dependency(site, filename, @context)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
# Internal: Adding the last build metadata file as a dependency ensures
|
74
|
+
# all pages using Vite assets are regenerated if a Vite build is triggered.
|
75
|
+
def last_build_metadata_path
|
76
|
+
ViteRuby.instance.builder.send(:last_build_path)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
# Public: Renders a path to a Vite asset.
|
81
|
+
class Jekyll::Vite::AssetPathTag < Jekyll::Vite::Tag
|
82
|
+
def render(context)
|
83
|
+
super { vite_asset_path(@file, @params) }
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
# Public: Renders the @vite/client script tag.
|
88
|
+
class Jekyll::Vite::ClientTag < Jekyll::Vite::Tag
|
89
|
+
def render(context)
|
90
|
+
return unless src = vite_manifest.vite_client_src
|
91
|
+
|
92
|
+
super {
|
93
|
+
tag :script, src: src, type: 'module'
|
94
|
+
}
|
95
|
+
end
|
96
|
+
|
97
|
+
def syntax_example
|
98
|
+
"{% #{ @tag_name } %}"
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
# Public: Renders a <link> tag for the specified stylesheet.
|
103
|
+
class Jekyll::Vite::StylesheetTag < Jekyll::Vite::Tag
|
104
|
+
def render(context)
|
105
|
+
super {
|
106
|
+
tag :link, **{
|
107
|
+
rel: 'stylesheet',
|
108
|
+
href: vite_asset_path(@file, type: :stylesheet),
|
109
|
+
media: 'screen',
|
110
|
+
}.merge(@params)
|
111
|
+
}
|
112
|
+
end
|
113
|
+
|
114
|
+
def syntax_example
|
115
|
+
"{% #{ @tag_name } application.scss media='screen, projection' %}"
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
# Public: Renders a <script> tag for the specified file.
|
120
|
+
class Jekyll::Vite::JavascriptTag < Jekyll::Vite::Tag
|
121
|
+
def render(context)
|
122
|
+
super {
|
123
|
+
media = @params.delete(:media) || 'screen'
|
124
|
+
crossorigin = @params.delete(:crossorigin) || 'anonymous'
|
125
|
+
type = @params.delete(:type) || 'module'
|
126
|
+
asset_type = @tag_name == 'vite_typescript_tag' ? :typescript : :javascript
|
127
|
+
|
128
|
+
entries = vite_manifest.resolve_entries(@file, type: asset_type)
|
129
|
+
|
130
|
+
[
|
131
|
+
script_tags(entries.fetch(:scripts), crossorigin: crossorigin, type: type, **@params),
|
132
|
+
link_tags(entries.fetch(:imports), rel: 'modulepreload', as: 'script', crossorigin: crossorigin, **@params),
|
133
|
+
link_tags(entries.fetch(:stylesheets), rel: 'stylesheet', media: media, crossorigin: crossorigin, **@params),
|
134
|
+
].join("\n")
|
135
|
+
}
|
136
|
+
end
|
137
|
+
|
138
|
+
def syntax_example
|
139
|
+
"{% #{ @tag_name } application %}"
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
# Recreating tag helpers in Jekyll requires considerably more code than in web
|
144
|
+
# frameworks, since Liquid does not provide HTML helpers and parsing parameters
|
145
|
+
# is more complex than a Ruby method invocation.
|
146
|
+
{
|
147
|
+
'vite_asset_path' => Jekyll::Vite::AssetPathTag,
|
148
|
+
'vite_client_tag' => Jekyll::Vite::ClientTag,
|
149
|
+
'vite_javascript_tag' => Jekyll::Vite::JavascriptTag,
|
150
|
+
'vite_typescript_tag' => Jekyll::Vite::JavascriptTag,
|
151
|
+
'vite_stylesheet_tag' => Jekyll::Vite::StylesheetTag,
|
152
|
+
}.each do |name, tag|
|
153
|
+
Liquid::Template.register_tag(name, tag)
|
154
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
{
|
2
|
+
"all": {
|
3
|
+
"sourceCodeDir": "_frontend",
|
4
|
+
"watchAdditionalPaths": []
|
5
|
+
},
|
6
|
+
"development": {
|
7
|
+
"autoBuild": true,
|
8
|
+
"publicOutputDir": "vite-dev",
|
9
|
+
"port": 3036
|
10
|
+
},
|
11
|
+
"test": {
|
12
|
+
"autoBuild": true,
|
13
|
+
"publicOutputDir": "vite-test"
|
14
|
+
}
|
15
|
+
}
|
metadata
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jekyll-vite
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Máximo Mussini
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-07-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: jekyll
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '5'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '3'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '5'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: vite_ruby
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: 1.2.14
|
40
|
+
- - "<"
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '2'
|
43
|
+
type: :runtime
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: 1.2.14
|
50
|
+
- - "<"
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '2'
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: rake
|
55
|
+
requirement: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
type: :development
|
61
|
+
prerelease: false
|
62
|
+
version_requirements: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
description:
|
68
|
+
email:
|
69
|
+
- maximomussini@gmail.com
|
70
|
+
executables: []
|
71
|
+
extensions: []
|
72
|
+
extra_rdoc_files: []
|
73
|
+
files:
|
74
|
+
- CHANGELOG.md
|
75
|
+
- LICENSE.txt
|
76
|
+
- README.md
|
77
|
+
- lib/jekyll/vite.rb
|
78
|
+
- lib/jekyll/vite/config.rb
|
79
|
+
- lib/jekyll/vite/generator.rb
|
80
|
+
- lib/jekyll/vite/installation.rb
|
81
|
+
- lib/jekyll/vite/proxy.rb
|
82
|
+
- lib/jekyll/vite/tags.rb
|
83
|
+
- lib/jekyll/vite/version.rb
|
84
|
+
- templates/config/jekyll-vite.json
|
85
|
+
homepage: https://github.com/ElMassimo/jekyll-vite
|
86
|
+
licenses:
|
87
|
+
- MIT
|
88
|
+
metadata:
|
89
|
+
source_code_uri: https://github.com/ElMassimo/jekyll-vite/tree/v0.0.1
|
90
|
+
changelog_uri: https://github.com/ElMassimo/jekyll-vite/blob/v0.0.1/CHANGELOG.md
|
91
|
+
post_install_message:
|
92
|
+
rdoc_options: []
|
93
|
+
require_paths:
|
94
|
+
- lib
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '2.4'
|
100
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
requirements: []
|
106
|
+
rubygems_version: 3.1.4
|
107
|
+
signing_key:
|
108
|
+
specification_version: 4
|
109
|
+
summary: Use Vite.js in Jekyll and enjoy a modern assets pipeline
|
110
|
+
test_files: []
|