vite_rails 1.0.11 → 1.0.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +11 -2
- data/lib/install/config/vite.config.ts +0 -3
- data/lib/vite_rails/config.rb +5 -0
- data/lib/vite_rails/helper.rb +4 -4
- data/lib/vite_rails/manifest.rb +16 -13
- data/lib/vite_rails/version.rb +1 -1
- data/package.json +2 -2
- data/test/dev_server_proxy_test.rb +1 -1
- data/test/helper_test.rb +17 -12
- data/test/manifest_test.rb +15 -9
- data/test/mounted_app/test/dummy/package.json +2 -2
- data/test/mounted_app/test/dummy/yarn.lock +8 -8
- data/test/test_app/public/vite-production/manifest-assets.json +10 -0
- data/test/test_app/public/vite-production/manifest.json +28 -11
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 57f866deafddde5401e02ec27cf751eb26a40a0be1fd832d9d3813fd7a69e721
|
4
|
+
data.tar.gz: 7cf22c583a3ac70f4353e227b0da4463b42067dd38f0c36774e665e619b31f2d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d101294de0e6f585b7df56c2881c465698f4c6ccbe8c4220117d7119c84f21e8b80e6aa2865dd353fa27b3b2c3d7a78095e80466c2d9b5f6eda60b6073a55ed0
|
7
|
+
data.tar.gz: fdbe92f7afafd6f82bafc6525a4099151efcdc385ce49e5cc5f696ea79efe5d411b6eaf093b9b1ec1402140a7d4ac34f629401fb70d9005535eaf38e989cf4cd
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
## Vite Rails 1.0.12 (2020-01-29)
|
2
|
+
|
3
|
+
- Add support for Vite 2.0.0-beta.56, which modified the manifest to output a `css` field in the manifest.
|
4
|
+
- Start generating an assets manifest, since 2.0.0-beta.51 stopped including non-JS entrypoints in the manifest.
|
5
|
+
|
1
6
|
## Vite Rails 1.0.11 (2020-01-24)
|
2
7
|
|
3
8
|
- Fix bug in `assetHost` that caused `base` to be configured incorrectly.
|
data/README.md
CHANGED
@@ -10,7 +10,7 @@
|
|
10
10
|
</a>
|
11
11
|
|
12
12
|
<br>
|
13
|
-
|
13
|
+
|
14
14
|
<p align="center">
|
15
15
|
<a href="https://github.com/ElMassimo/vite_rails/actions">
|
16
16
|
<img alt="Build Status" src="https://github.com/ElMassimo/vite_rails/workflows/build/badge.svg"/>
|
@@ -41,6 +41,8 @@
|
|
41
41
|
[config file]: https://github.com/ElMassimo/vite_rails/blob/main/package/default.vite.json
|
42
42
|
[example app]: https://github.com/ElMassimo/vite_rails/tree/main/examples/blog
|
43
43
|
[heroku]: https://vite-rails-demo.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
|
44
46
|
|
45
47
|
[__Vite Rails__][vite_rails] allows you to use [Vite] to power the frontend of your Rails app.
|
46
48
|
|
@@ -50,7 +52,7 @@ Check an [example app] running on [Heroku].
|
|
50
52
|
|
51
53
|
## Features ⚡️
|
52
54
|
|
53
|
-
-
|
55
|
+
- 💡 Instant server start
|
54
56
|
- ⚡️ Blazing fast hot reload
|
55
57
|
- 🚀 Zero-config deployments
|
56
58
|
- 🤝 Integrated with <kbd>assets:precompile</kbd>
|
@@ -94,6 +96,13 @@ Visit any page and you should see a printed console output: `Vite ⚡️ Rails`.
|
|
94
96
|
|
95
97
|
For more [guides] and a full [configuration reference], check the [documentation website][website].
|
96
98
|
|
99
|
+
## Contact ✉️
|
100
|
+
|
101
|
+
Please use [Issues] to report bugs you find, and [Discussions] to make feature requests or get help.
|
102
|
+
|
103
|
+
Don't hesitate to _⭐️ star the project_ if you find it useful!
|
104
|
+
|
105
|
+
|
97
106
|
## Special Thanks 🙏
|
98
107
|
|
99
108
|
- [webpacker]
|
data/lib/vite_rails/config.rb
CHANGED
@@ -24,6 +24,11 @@ class ViteRails::Config
|
|
24
24
|
build_output_dir.join('manifest.json')
|
25
25
|
end
|
26
26
|
|
27
|
+
# Internal: Path where vite-plugin-ruby outputs the assets manifest file.
|
28
|
+
def assets_manifest_path
|
29
|
+
build_output_dir.join('manifest-assets.json')
|
30
|
+
end
|
31
|
+
|
27
32
|
# Public: The directory where Vite will store the built assets.
|
28
33
|
def build_output_dir
|
29
34
|
root.join(public_dir, public_output_dir)
|
data/lib/vite_rails/helper.rb
CHANGED
@@ -35,15 +35,15 @@ module ViteRails::Helper
|
|
35
35
|
js_entries = names.map { |name| current_vite_instance.manifest.lookup!(name, type: asset_type) }
|
36
36
|
js_tags = javascript_include_tag(*js_entries.map { |entry| entry['file'] }, crossorigin: crossorigin, type: type, **options)
|
37
37
|
|
38
|
+
preload_entries = js_entries.flat_map { |entry| entry['imports'] }.compact.uniq
|
39
|
+
|
38
40
|
unless skip_preload_tags || current_vite_instance.dev_server_running?
|
39
|
-
preload_paths =
|
41
|
+
preload_paths = preload_entries.map { |entry| entry['file'] }.compact.uniq
|
40
42
|
preload_tags = preload_paths.map { |path| preload_link_tag(path, crossorigin: crossorigin) }
|
41
43
|
end
|
42
44
|
|
43
45
|
unless skip_style_tags || current_vite_instance.dev_server_running?
|
44
|
-
style_paths =
|
45
|
-
current_vite_instance.manifest.lookup(name.delete_suffix('.js'), type: :stylesheet)&.fetch('file')
|
46
|
-
}.compact
|
46
|
+
style_paths = (js_entries + preload_entries).flat_map { |entry| entry['css'] }.compact.uniq
|
47
47
|
style_tags = stylesheet_link_tag(*style_paths)
|
48
48
|
end
|
49
49
|
|
data/lib/vite_rails/manifest.rb
CHANGED
@@ -37,7 +37,7 @@ class ViteRails::Manifest
|
|
37
37
|
find_manifest_entry(with_file_extension(name, type))
|
38
38
|
end
|
39
39
|
|
40
|
-
# Public: Refreshes the cached mappings by reading the updated manifest.
|
40
|
+
# Public: Refreshes the cached mappings by reading the updated manifest files.
|
41
41
|
def refresh
|
42
42
|
@manifest = load_manifest
|
43
43
|
end
|
@@ -81,15 +81,18 @@ private
|
|
81
81
|
@manifest ||= load_manifest
|
82
82
|
end
|
83
83
|
|
84
|
-
# Internal:
|
84
|
+
# Internal: Loads and merges the manifest files, resolving the asset paths.
|
85
85
|
def load_manifest
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
86
|
+
files = [config.manifest_path, config.assets_manifest_path].select(&:exist?)
|
87
|
+
files.map { |path| JSON.parse(path.read) }.inject({}, &:merge).tap(&method(:resolve_references))
|
88
|
+
end
|
89
|
+
|
90
|
+
# Internal: Resolves the paths that reference a manifest entry.
|
91
|
+
def resolve_references(manifest)
|
92
|
+
manifest.each_value do |entry|
|
93
|
+
entry['file'] = prefix_vite_asset(entry['file'])
|
94
|
+
entry['css'] = Array.wrap(entry['css']).map { |path| prefix_vite_asset(path) } if entry['css']
|
95
|
+
entry['imports']&.map! { |name| manifest.fetch(name) }
|
93
96
|
end
|
94
97
|
end
|
95
98
|
|
@@ -106,7 +109,7 @@ private
|
|
106
109
|
case entry_type
|
107
110
|
when :javascript then 'js'
|
108
111
|
when :stylesheet then 'css'
|
109
|
-
when :typescript then
|
112
|
+
when :typescript then 'ts'
|
110
113
|
else entry_type
|
111
114
|
end
|
112
115
|
end
|
@@ -115,12 +118,12 @@ private
|
|
115
118
|
def missing_entry_error(name, type: nil, **_options)
|
116
119
|
file_name = with_file_extension(name, type)
|
117
120
|
raise ViteRails::Manifest::MissingEntryError, <<~MSG
|
118
|
-
Vite Rails can't find #{ file_name } in #{ config.manifest_path }.
|
121
|
+
Vite Rails can't find #{ file_name } in #{ config.manifest_path } or #{ config.assets_manifest_path }.
|
119
122
|
|
120
123
|
Possible causes:
|
121
124
|
#{ missing_entry_causes.map { |cause| "\t- #{ cause }" }.join("\n") }
|
122
125
|
|
123
|
-
|
126
|
+
Content in your manifests:
|
124
127
|
#{ JSON.pretty_generate(@manifest) }
|
125
128
|
MSG
|
126
129
|
end
|
@@ -133,7 +136,7 @@ private
|
|
133
136
|
(local && !dev_server_running? && 'The Vite development server has crashed or is no longer available.'),
|
134
137
|
'You have misconfigured config/vite.json file.',
|
135
138
|
(!local && 'Assets have not been precompiled'),
|
136
|
-
].
|
139
|
+
].select(&:present?)
|
137
140
|
rescue StandardError
|
138
141
|
[]
|
139
142
|
end
|
data/lib/vite_rails/version.rb
CHANGED
data/package.json
CHANGED
data/test/helper_test.rb
CHANGED
@@ -27,33 +27,32 @@ class HelperTest < ActionView::TestCase
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def test_vite_asset_path
|
30
|
-
assert_equal '/vite-production/assets/
|
31
|
-
assert_equal '/vite-production/assets/
|
30
|
+
assert_equal '/vite-production/assets/application.d9514acc.js', vite_asset_path('application.ts')
|
31
|
+
assert_equal '/vite-production/assets/styles.0e53e684.css', vite_asset_path('styles.css')
|
32
32
|
with_dev_server_running {
|
33
|
-
assert_equal '/vite-production/
|
34
|
-
assert_equal '/vite-production/
|
33
|
+
assert_equal '/vite-production/application.ts', vite_asset_path('application.ts')
|
34
|
+
assert_equal '/vite-production/styles.css', vite_asset_path('styles.css')
|
35
35
|
}
|
36
36
|
end
|
37
37
|
|
38
38
|
def test_vite_stylesheet_tag
|
39
|
-
assert_equal
|
40
|
-
vite_stylesheet_tag('colored')
|
39
|
+
assert_equal link(href: '/vite-production/assets/styles.0e53e684.css'), vite_stylesheet_tag('styles')
|
41
40
|
|
42
|
-
assert_equal vite_stylesheet_tag('
|
41
|
+
assert_equal vite_stylesheet_tag('styles'), vite_stylesheet_tag('styles.css')
|
43
42
|
|
44
43
|
with_dev_server_running {
|
45
|
-
assert_equal
|
46
|
-
vite_stylesheet_tag('colored')
|
44
|
+
assert_equal link(href: '/vite-production/styles.css'), vite_stylesheet_tag('styles')
|
47
45
|
|
48
|
-
assert_equal vite_stylesheet_tag('
|
46
|
+
assert_equal vite_stylesheet_tag('styles'), vite_stylesheet_tag('styles.css')
|
49
47
|
}
|
50
48
|
end
|
51
49
|
|
52
50
|
def test_vite_javascript_tag
|
53
51
|
assert_equal [
|
54
|
-
%(<script src="/vite-production/assets/application.
|
52
|
+
%(<script src="/vite-production/assets/application.d9514acc.js" crossorigin="anonymous" type="module"></script>),
|
53
|
+
%(<link rel="preload" href="/vite-production/assets/vendor.880705da.js" as="script" type="text/javascript" crossorigin="anonymous">),
|
55
54
|
%(<link rel="preload" href="/vite-production/assets/example_import.8e1fddc0.js" as="script" type="text/javascript" crossorigin="anonymous">),
|
56
|
-
|
55
|
+
link(href: '/vite-production/assets/application.f510c1e9.css'),
|
57
56
|
].join, vite_javascript_tag('application')
|
58
57
|
|
59
58
|
assert_equal vite_javascript_tag('application'), vite_javascript_tag('application.js')
|
@@ -67,4 +66,10 @@ class HelperTest < ActionView::TestCase
|
|
67
66
|
vite_typescript_tag('application')
|
68
67
|
}
|
69
68
|
end
|
69
|
+
|
70
|
+
def link(href:, rel: 'stylesheet', media: 'screen')
|
71
|
+
attrs = [%(media="#{ media }"), %(href="#{ href }")]
|
72
|
+
attrs.reverse! if Rails.gem_version > Gem::Version.new('6.1.1')
|
73
|
+
%(<link rel="#{ rel }" #{ attrs.join(' ') } />)
|
74
|
+
end
|
70
75
|
end
|
data/test/manifest_test.rb
CHANGED
@@ -25,13 +25,19 @@ class ManifestTest < ViteRails::Test
|
|
25
25
|
|
26
26
|
def test_lookup_success!
|
27
27
|
entry = {
|
28
|
-
'file' => '/vite-production/assets/application.
|
28
|
+
'file' => '/vite-production/assets/application.d9514acc.js',
|
29
|
+
'src' => 'application.js',
|
30
|
+
'isEntry' => true,
|
29
31
|
'imports' => [
|
30
|
-
'/vite-production/assets/
|
32
|
+
{ 'file' => '/vite-production/assets/vendor.880705da.js' },
|
33
|
+
{ 'file' => '/vite-production/assets/example_import.8e1fddc0.js', 'src' => 'example_import.js', 'isEntry' => true },
|
34
|
+
],
|
35
|
+
'css' => [
|
36
|
+
'/vite-production/assets/application.f510c1e9.css',
|
31
37
|
],
|
32
38
|
}
|
33
39
|
assert_equal entry, ViteRails.manifest.lookup!('application.js', type: :javascript)
|
34
|
-
assert_equal entry, ViteRails.manifest.lookup!('application', type: :typescript)
|
40
|
+
assert_equal entry.merge('src' => 'application.ts'), ViteRails.manifest.lookup!('application', type: :typescript)
|
35
41
|
end
|
36
42
|
|
37
43
|
def test_lookup_success_with_dev_server_running!
|
@@ -50,16 +56,16 @@ class ManifestTest < ViteRails::Test
|
|
50
56
|
end
|
51
57
|
|
52
58
|
def test_lookup_success
|
53
|
-
entry = { 'file' => '/vite-production/assets/
|
54
|
-
assert_equal entry, ViteRails.manifest.lookup('
|
55
|
-
assert_equal entry, ViteRails.manifest.lookup('
|
56
|
-
assert_equal entry, ViteRails.manifest.lookup('
|
59
|
+
entry = { 'file' => '/vite-production/assets/styles.0e53e684.css', 'src' => 'styles.css' }
|
60
|
+
assert_equal entry, ViteRails.manifest.lookup('styles.css')
|
61
|
+
assert_equal entry, ViteRails.manifest.lookup('styles.css', type: :stylesheet)
|
62
|
+
assert_equal entry, ViteRails.manifest.lookup('styles', type: :stylesheet)
|
57
63
|
end
|
58
64
|
|
59
65
|
def test_lookup_success_with_dev_server_running
|
60
|
-
entry = { 'file' => '/vite-production/
|
66
|
+
entry = { 'file' => '/vite-production/styles.css' }
|
61
67
|
with_dev_server_running {
|
62
|
-
assert_equal entry, ViteRails.manifest.lookup('
|
68
|
+
assert_equal entry, ViteRails.manifest.lookup('styles', type: :stylesheet)
|
63
69
|
}
|
64
70
|
end
|
65
71
|
|
@@ -188,17 +188,17 @@ to-regex-range@^5.0.1:
|
|
188
188
|
dependencies:
|
189
189
|
is-number "^7.0.0"
|
190
190
|
|
191
|
-
vite-plugin-ruby@^1.0.
|
192
|
-
version "1.0.
|
193
|
-
resolved "https://registry.yarnpkg.com/vite-plugin-ruby/-/vite-plugin-ruby-1.0.
|
194
|
-
integrity sha512-
|
191
|
+
vite-plugin-ruby@^1.0.6:
|
192
|
+
version "1.0.6"
|
193
|
+
resolved "https://registry.yarnpkg.com/vite-plugin-ruby/-/vite-plugin-ruby-1.0.6.tgz#7ecaf2b8ad4237096c631587e7170c4ce95c0a26"
|
194
|
+
integrity sha512-wJ0Djf/t1bqaowO14ceeNKeqgKW69WwNHboV/Gxq+66NpuDSm8jLKRtm+CiqnvlT9fK5NCiNwtyFkgsKbKAH/g==
|
195
195
|
dependencies:
|
196
196
|
fast-glob "^3.2.4"
|
197
197
|
|
198
|
-
vite@^2.0.0-beta.
|
199
|
-
version "2.0.0-beta.
|
200
|
-
resolved "https://registry.yarnpkg.com/vite/-/vite-2.0.0-beta.
|
201
|
-
integrity sha512-
|
198
|
+
vite@^2.0.0-beta.56:
|
199
|
+
version "2.0.0-beta.56"
|
200
|
+
resolved "https://registry.yarnpkg.com/vite/-/vite-2.0.0-beta.56.tgz#b254ec4647ae1383d7c5b6f3fdb01f8971b5bcdd"
|
201
|
+
integrity sha512-MX20PSXT6wTfq37B9d/iTmfAut4kBT6DOquw60zVFRtnO7hR9sNmkM6pmoNyVuYJrlkhKZZqoO2DnYs3C7LKCw==
|
202
202
|
dependencies:
|
203
203
|
esbuild "^0.8.34"
|
204
204
|
postcss "^8.2.1"
|
@@ -1,22 +1,39 @@
|
|
1
1
|
{
|
2
2
|
"application.js": {
|
3
|
-
"file": "assets/application.
|
3
|
+
"file": "assets/application.d9514acc.js",
|
4
|
+
"src": "application.js",
|
5
|
+
"isEntry": true,
|
4
6
|
"imports": [
|
5
|
-
"
|
7
|
+
"_vendor.880705da.js",
|
8
|
+
"example_import.js"
|
9
|
+
],
|
10
|
+
"css": [
|
11
|
+
"assets/application.f510c1e9.css"
|
12
|
+
]
|
13
|
+
},
|
14
|
+
"application.ts": {
|
15
|
+
"file": "assets/application.d9514acc.js",
|
16
|
+
"src": "application.ts",
|
17
|
+
"isEntry": true,
|
18
|
+
"imports": [
|
19
|
+
"_vendor.880705da.js",
|
20
|
+
"example_import.js"
|
21
|
+
],
|
22
|
+
"css": [
|
23
|
+
"assets/application.f510c1e9.css"
|
6
24
|
]
|
7
25
|
},
|
8
26
|
"example_import.js": {
|
9
27
|
"file": "assets/example_import.8e1fddc0.js",
|
10
|
-
"
|
11
|
-
|
12
|
-
"colored.js": {
|
13
|
-
"file": "assets/colored.1173bfe0.js",
|
14
|
-
"imports": []
|
28
|
+
"src": "example_import.js",
|
29
|
+
"isEntry": true
|
15
30
|
},
|
16
|
-
"
|
17
|
-
"file": "assets/
|
31
|
+
"logo.svg": {
|
32
|
+
"file": "assets/logo.f1745d22.js",
|
33
|
+
"src": "logo.svg",
|
34
|
+
"isEntry": true
|
18
35
|
},
|
19
|
-
"
|
20
|
-
"file": "assets/
|
36
|
+
"_vendor.880705da.js": {
|
37
|
+
"file": "assets/vendor.880705da.js"
|
21
38
|
}
|
22
39
|
}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vite_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Máximo Mussini
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-01-
|
11
|
+
date: 2021-01-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -177,6 +177,7 @@ files:
|
|
177
177
|
- test/test_app/config/vite_additional_paths.json
|
178
178
|
- test/test_app/config/vite_public_dir.json
|
179
179
|
- test/test_app/package.json
|
180
|
+
- test/test_app/public/vite-production/manifest-assets.json
|
180
181
|
- test/test_app/public/vite-production/manifest.json
|
181
182
|
- test/test_app/some.config.js
|
182
183
|
- test/test_app/yarn.lock
|
@@ -185,8 +186,8 @@ homepage: https://github.com/ElMassimo/vite_rails
|
|
185
186
|
licenses:
|
186
187
|
- MIT
|
187
188
|
metadata:
|
188
|
-
source_code_uri: https://github.com/ElMassimo/vite_rails/tree/v1.0.
|
189
|
-
changelog_uri: https://github.com/ElMassimo/vite_rails/blob/v1.0.
|
189
|
+
source_code_uri: https://github.com/ElMassimo/vite_rails/tree/v1.0.12
|
190
|
+
changelog_uri: https://github.com/ElMassimo/vite_rails/blob/v1.0.12/CHANGELOG.md
|
190
191
|
post_install_message:
|
191
192
|
rdoc_options: []
|
192
193
|
require_paths:
|
@@ -238,6 +239,7 @@ test_files:
|
|
238
239
|
- test/test_app/config/vite_additional_paths.json
|
239
240
|
- test/test_app/config/vite_public_dir.json
|
240
241
|
- test/test_app/package.json
|
242
|
+
- test/test_app/public/vite-production/manifest-assets.json
|
241
243
|
- test/test_app/public/vite-production/manifest.json
|
242
244
|
- test/test_app/some.config.js
|
243
245
|
- test/test_app/yarn.lock
|