vite_hanami 0.5.0
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 +3 -0
- data/CONTRIBUTING.md +33 -0
- data/LICENSE.txt +21 -0
- data/README.md +108 -0
- data/lib/vite_hanami.rb +5 -0
- data/lib/vite_hanami/installation.rb +35 -0
- data/lib/vite_hanami/tag_helpers.rb +76 -0
- data/lib/vite_hanami/version.rb +5 -0
- data/templates/config/hanami-vite.json +15 -0
- metadata +110 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8bed5de3195c146f3e7826478b064fdcc2356e76b37ae4f828592babc50a5e79
|
4
|
+
data.tar.gz: 1ad190f5198116cfdc4227221f07ee948d6651a069c68c3c377108aee2fa60be
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b522acfcb73ec7206b497d57ab2dd999e8ad7034bdcc963dbb21b8f2ef72c9e23f5b87ff6fa04fc1735d1b61b90ab2460e432c23d9b289e9850aef1d4c30a1d5
|
7
|
+
data.tar.gz: 2660390dbef9a773ce0cc566663a22178d197fb33c5fa3073ee28f7a81850f16acd4cb9fb04655a14cb229a721ab61ed94ad0bb94a71d6eda764fea409dedaac
|
data/CHANGELOG.md
ADDED
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
## Setting Up a Development Environment
|
2
|
+
|
3
|
+
1. Install [Yarn](https://yarnpkg.com/)
|
4
|
+
|
5
|
+
2. Run the following commands to set up the development environment.
|
6
|
+
|
7
|
+
```
|
8
|
+
bundle install
|
9
|
+
```
|
10
|
+
|
11
|
+
## Making sure your changes pass all tests
|
12
|
+
There are a number of automated checks which run on GitHub Actions when a pull request is created.
|
13
|
+
You can run those checks on your own locally to make sure that your changes would not break the CI build.
|
14
|
+
|
15
|
+
### 1. Check the code for JavaScript style violations
|
16
|
+
```
|
17
|
+
yarn lint
|
18
|
+
```
|
19
|
+
|
20
|
+
### 2. Check the code for Ruby style violations
|
21
|
+
```
|
22
|
+
bundle exec rubocop
|
23
|
+
```
|
24
|
+
|
25
|
+
### 3. Run the JavaScript test suite
|
26
|
+
```
|
27
|
+
yarn test
|
28
|
+
```
|
29
|
+
|
30
|
+
### 4. Run the Ruby test suite
|
31
|
+
```
|
32
|
+
bundle exec rake test
|
33
|
+
```
|
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,108 @@
|
|
1
|
+
<h1 align="center">
|
2
|
+
<a href="https://vite-rails.netlify.app/">
|
3
|
+
<img src="https://raw.githubusercontent.com/ElMassimo/vite_rails/main/docs/public/logo.svg" width="120px"/>
|
4
|
+
</a>
|
5
|
+
|
6
|
+
<br>
|
7
|
+
|
8
|
+
<a href="https://vite-rails.netlify.app/">
|
9
|
+
Vite Hanami
|
10
|
+
</a>
|
11
|
+
|
12
|
+
<br>
|
13
|
+
|
14
|
+
<p align="center">
|
15
|
+
<a href="https://github.com/ElMassimo/vite_rails/actions">
|
16
|
+
<img alt="Build Status" src="https://github.com/ElMassimo/vite_rails/workflows/build/badge.svg"/>
|
17
|
+
</a>
|
18
|
+
<a href="https://codeclimate.com/github/ElMassimo/vite_rails">
|
19
|
+
<img alt="Maintainability" src="https://codeclimate.com/github/ElMassimo/vite_rails/badges/gpa.svg"/>
|
20
|
+
</a>
|
21
|
+
<a href="https://codeclimate.com/github/ElMassimo/vite_rails">
|
22
|
+
<img alt="Test Coverage" src="https://codeclimate.com/github/ElMassimo/vite_rails/badges/coverage.svg"/>
|
23
|
+
</a>
|
24
|
+
<a href="https://rubygems.org/gems/vite_hanami">
|
25
|
+
<img alt="Gem Version" src="https://img.shields.io/gem/v/vite_hanami.svg?colorB=e9573f"/>
|
26
|
+
</a>
|
27
|
+
<a href="https://github.com/ElMassimo/vite_rails/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://vite-rails.netlify.app/
|
34
|
+
[configuration reference]: https://vite-rails.netlify.app/config/
|
35
|
+
[features]: https://vite-rails.netlify.app/guide/introduction.html
|
36
|
+
[guides]: https://vite-rails.netlify.app/guide/
|
37
|
+
[config]: https://vite-rails.netlify.app/config/
|
38
|
+
[vite_rails]: https://github.com/ElMassimo/vite_rails
|
39
|
+
[webpacker]: https://github.com/rails/webpacker
|
40
|
+
[vite]: http://vitejs.dev/
|
41
|
+
[config file]: https://github.com/ElMassimo/vite_rails/blob/main/vite-plugin-ruby/default.vite.json
|
42
|
+
[example app]: https://github.com/ElMassimo/pingcrm-vite
|
43
|
+
[heroku]: https://pingcrm-vite.herokuapp.com/
|
44
|
+
[Issues]: https://github.com/ElMassimo/vite_rails/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc
|
45
|
+
[Discussions]: https://github.com/ElMassimo/vite_rails/discussions
|
46
|
+
[vite_rails]: https://github.com/ElMassimo/vite_rails/tree/main/vite_rails
|
47
|
+
[vite_ruby]: https://github.com/ElMassimo/vite_rails/tree/main/vite_ruby
|
48
|
+
[vite_hanami]: https://github.com/ElMassimo/vite_rails/tree/main/vite_hanami
|
49
|
+
|
50
|
+
|
51
|
+
[Vite] is to frontend tooling as Ruby to programming, pure joy! 😍
|
52
|
+
|
53
|
+
This library provides specific installation scripts for Hanami, as well as idiomatic tag helpers.
|
54
|
+
|
55
|
+
## Features ⚡️
|
56
|
+
|
57
|
+
- 💡 Instant server start
|
58
|
+
- ⚡️ Blazing fast hot reload
|
59
|
+
- 🚀 Zero-config deployments
|
60
|
+
- 🤝 Integrated with <kbd>assets:precompile</kbd>
|
61
|
+
- [And more!][features]
|
62
|
+
|
63
|
+
## Documentation 📖
|
64
|
+
|
65
|
+
Visit the [documentation website][website] to check out the [guides] and searchable [configuration reference].
|
66
|
+
|
67
|
+
## Installation 💿
|
68
|
+
|
69
|
+
Add this line to your application's Gemfile:
|
70
|
+
|
71
|
+
```ruby
|
72
|
+
gem 'vite_hanami'
|
73
|
+
```
|
74
|
+
|
75
|
+
Then, run:
|
76
|
+
|
77
|
+
```bash
|
78
|
+
bundle install
|
79
|
+
bundle exec vite install
|
80
|
+
```
|
81
|
+
|
82
|
+
This will generate configuration files and a sample setup.
|
83
|
+
|
84
|
+
Additional installation instructions are available in the [documentation website][website].
|
85
|
+
|
86
|
+
## Getting Started 💻
|
87
|
+
|
88
|
+
Restart your Hanami web server, and then run <kbd>bin/vite dev</kbd> to start the Vite development server.
|
89
|
+
|
90
|
+
Visit any page and you should see a printed console output: `Vite ⚡️ Ruby`.
|
91
|
+
|
92
|
+
For more [guides] and a full [configuration reference], check the [documentation website][website].
|
93
|
+
|
94
|
+
## Contact ✉️
|
95
|
+
|
96
|
+
Please use [Issues] to report bugs you find, and [Discussions] to make feature requests or get help.
|
97
|
+
|
98
|
+
Don't hesitate to _⭐️ star the project_ if you find it useful!
|
99
|
+
|
100
|
+
|
101
|
+
## Special Thanks 🙏
|
102
|
+
|
103
|
+
- [webpacker]
|
104
|
+
- [vite]
|
105
|
+
|
106
|
+
## License
|
107
|
+
|
108
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/lib/vite_hanami.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'vite_hanami'
|
4
|
+
|
5
|
+
# Internal: Extends the base installation script from Vite Ruby to work for a
|
6
|
+
# typical Hanami app.
|
7
|
+
module ViteHanami::Installation
|
8
|
+
HANAMI_TEMPLATES = Pathname.new(File.expand_path('../../templates', __dir__))
|
9
|
+
|
10
|
+
# Override: Setup a typical apps/web Hanami app to use Vite.
|
11
|
+
def setup_app_files
|
12
|
+
cp HANAMI_TEMPLATES.join('config/hanami-vite.json'), config.config_path
|
13
|
+
inject_line_after root.join('config/environment.rb'), 'environment :development do', ' middleware.use(ViteRuby::DevServerProxy, ssl_verify_none: true) if ViteRuby.run_proxy?'
|
14
|
+
inject_line_after_last root.join('apps/web/application.rb'), 'include Web::Assets::Helpers', ' include ViteHanami::TagHelpers'
|
15
|
+
inject_line_after root.join('apps/web/application.rb'), 'configure :development do', <<-CSP
|
16
|
+
# Allow @vite/client to hot reload changes in development
|
17
|
+
security.content_security_policy(
|
18
|
+
security.content_security_policy
|
19
|
+
.sub('script-src', "script-src 'unsafe-eval'")
|
20
|
+
.sub('connect-src', "connect-src ws://\#{ ViteRuby.config.host_with_port }")
|
21
|
+
)
|
22
|
+
CSP
|
23
|
+
end
|
24
|
+
|
25
|
+
# Override: Inject the vite client and sample script to the default HTML template.
|
26
|
+
def install_sample_files
|
27
|
+
super
|
28
|
+
inject_line_before root.join('apps/web/templates/application.html.erb'), '</head>', <<-HTML
|
29
|
+
<%= vite_client %>
|
30
|
+
<%= vite_javascript 'application' %>
|
31
|
+
HTML
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
ViteRuby::CLI::Install.prepend(ViteHanami::Installation)
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Public: Allows to render HTML tags for scripts and styles processed by Vite.
|
4
|
+
module ViteHanami::TagHelpers
|
5
|
+
# Public: Renders a script tag for vite/client to enable HMR in development.
|
6
|
+
def vite_client
|
7
|
+
return unless src = vite_manifest.vite_client_src
|
8
|
+
|
9
|
+
html.script(src: src, type: 'module')
|
10
|
+
end
|
11
|
+
|
12
|
+
# Public: Resolves the path for the specified Vite asset.
|
13
|
+
#
|
14
|
+
# Example:
|
15
|
+
# <%= vite_asset_path 'calendar.css' %> # => "/vite/assets/calendar-1016838bab065ae1e122.css"
|
16
|
+
def vite_asset_path(name, **options)
|
17
|
+
asset_path vite_manifest.path_for(name, **options)
|
18
|
+
end
|
19
|
+
|
20
|
+
# Public: Renders a <script> tag for the specified Vite entrypoints.
|
21
|
+
def vite_javascript(*names,
|
22
|
+
type: 'module',
|
23
|
+
asset_type: :javascript,
|
24
|
+
skip_preload_tags: false,
|
25
|
+
skip_style_tags: false,
|
26
|
+
crossorigin: 'anonymous',
|
27
|
+
**options)
|
28
|
+
entries = vite_manifest.resolve_entries(*names, type: asset_type)
|
29
|
+
tags = javascript(*entries.fetch(:scripts), crossorigin: crossorigin, type: type, **options)
|
30
|
+
tags << vite_modulepreload(*entries.fetch(:imports), crossorigin: crossorigin) unless skip_preload_tags
|
31
|
+
tags << stylesheet(*entries.fetch(:stylesheets)) unless skip_style_tags
|
32
|
+
::Hanami::Utils::Escape::SafeString.new(tags)
|
33
|
+
end
|
34
|
+
|
35
|
+
# Public: Renders a <script> tag for the specified Vite entrypoints.
|
36
|
+
def vite_typescript(*names, **options)
|
37
|
+
vite_javascript(*names, asset_type: :typescript, **options)
|
38
|
+
end
|
39
|
+
|
40
|
+
# Public: Renders a <link> tag for the specified Vite entrypoints.
|
41
|
+
def vite_stylesheet(*names, **options)
|
42
|
+
style_paths = names.map { |name| vite_asset_path(name, type: :stylesheet) }
|
43
|
+
stylesheet(*style_paths, **options)
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
# Internal: Returns the current manifest loaded by Vite Ruby.
|
49
|
+
def vite_manifest
|
50
|
+
ViteRuby.instance.manifest
|
51
|
+
end
|
52
|
+
|
53
|
+
# Internal: The leading path to every Vite asset.
|
54
|
+
def vite_assets_prefix
|
55
|
+
"/#{ ViteRuby.instance.config.public_output_dir }"
|
56
|
+
end
|
57
|
+
|
58
|
+
# Internal: Renders a modulepreload link tag.
|
59
|
+
def vite_modulepreload(*sources, crossorigin:)
|
60
|
+
_safe_tags(*sources) { |source|
|
61
|
+
href = asset_path(source)
|
62
|
+
_push_promise(href, as: :script)
|
63
|
+
html.link(rel: 'modulepreload', href: href, as: :script, crossorigin: crossorigin)
|
64
|
+
}
|
65
|
+
end
|
66
|
+
|
67
|
+
# Override: Hanami doesn't play nice with non-managed assets, it will always
|
68
|
+
# prefix them and there's no configuration option to avoid it.
|
69
|
+
def _relative_url(source)
|
70
|
+
if self.class.assets_configuration.cdn || !source.to_s.start_with?(vite_assets_prefix)
|
71
|
+
self.class.assets_configuration.asset_path(source)
|
72
|
+
else
|
73
|
+
Hanami::Utils::PathPrefix.new('/').join(source).to_s
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
{
|
2
|
+
"all": {
|
3
|
+
"sourceCodeDir": "apps/web/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: vite_hanami
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Máximo Mussini
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-02-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: vite_ruby
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.3.0
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.3.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rubocop
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubocop-performance
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- maximomussini@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- CHANGELOG.md
|
77
|
+
- CONTRIBUTING.md
|
78
|
+
- LICENSE.txt
|
79
|
+
- README.md
|
80
|
+
- lib/vite_hanami.rb
|
81
|
+
- lib/vite_hanami/installation.rb
|
82
|
+
- lib/vite_hanami/tag_helpers.rb
|
83
|
+
- lib/vite_hanami/version.rb
|
84
|
+
- templates/config/hanami-vite.json
|
85
|
+
homepage: https://github.com/ElMassimo/vite_rails
|
86
|
+
licenses:
|
87
|
+
- MIT
|
88
|
+
metadata:
|
89
|
+
source_code_uri: https://github.com/ElMassimo/vite_rails/tree/vite_hanami@0.5.0/vite_hanami
|
90
|
+
changelog_uri: https://github.com/ElMassimo/vite_rails/blob/vite_hanami@0.5.0/vite_hanami/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.5'
|
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 in Hanami and bring joy to your JavaScript experience
|
110
|
+
test_files: []
|