minivite_rails 0.1.1 → 0.2.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 +4 -4
- data/.editorconfig +8 -0
- data/.rubocop.yml +16 -1
- data/.ruby-version +1 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +79 -40
- data/README.md +12 -4
- data/Rakefile +1 -1
- data/lib/minivite_rails/configuration.rb +8 -9
- data/lib/minivite_rails/manifest.rb +32 -28
- data/lib/minivite_rails/tag_helpers.rb +38 -21
- data/lib/minivite_rails/version.rb +1 -1
- metadata +14 -90
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8e417fde65bd798b667b0218f41c60e56d8ddd40a8b98cc14bcdfbb90cee20b3
|
4
|
+
data.tar.gz: dce35afe2703eeca8905eab9fa3ebb387952bbc165324b9009af0574c49d4ff4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f21100117904f4020589f7e86c3698135e2430b11650d6fd20c9c0cb331b4b66d459175134752ecfec13179ebb355fc18dc12841529ca033460c9476f417fa5a
|
7
|
+
data.tar.gz: 73add9b6912dd42500ace7b5b707d359e031345096314194f9c23c97d33bcad5ddb8f9a2ffad2bbfbe87d7d0d1fa3100e0623ed3cddf7b3e1a7a4d8dba89b6dc
|
data/.editorconfig
ADDED
data/.rubocop.yml
CHANGED
@@ -1,12 +1,27 @@
|
|
1
1
|
require: rubocop-rspec
|
2
2
|
|
3
|
+
inherit_mode:
|
4
|
+
merge:
|
5
|
+
- Exclude
|
6
|
+
|
3
7
|
AllCops:
|
4
8
|
NewCops: enable
|
5
|
-
TargetRubyVersion: 3.
|
9
|
+
TargetRubyVersion: 3.1
|
10
|
+
Exclude:
|
11
|
+
- example/app/assets/**/*
|
12
|
+
- example/bin/*
|
13
|
+
- example/db/*schema.rb
|
14
|
+
- example/log/**/*
|
15
|
+
- example/public/**/*
|
16
|
+
- example/storage/**/*
|
17
|
+
|
6
18
|
|
7
19
|
Layout/LineLength:
|
8
20
|
Max: 120
|
9
21
|
|
22
|
+
Style/Documentation:
|
23
|
+
Enabled: false
|
24
|
+
|
10
25
|
Metrics/ClassLength:
|
11
26
|
Max: 200
|
12
27
|
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.3.0
|
data/Gemfile
CHANGED
@@ -4,3 +4,11 @@ source 'https://rubygems.org'
|
|
4
4
|
|
5
5
|
# Specify your gem's dependencies in minivite_rails.gemspec
|
6
6
|
gemspec
|
7
|
+
|
8
|
+
gem 'debug', '>= 1.0.0'
|
9
|
+
gem 'rake', '~> 13.1'
|
10
|
+
gem 'rspec', '~> 3.13'
|
11
|
+
gem 'rubocop', '~> 1.60', require: false
|
12
|
+
gem 'rubocop-rspec', '~> 2.26', require: false
|
13
|
+
gem 'rubocop-rubycw', require: false
|
14
|
+
gem 'solargraph'
|
data/Gemfile.lock
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
minivite_rails (0.
|
5
|
-
|
6
|
-
railties (>= 6.0.0)
|
4
|
+
minivite_rails (0.2.0)
|
5
|
+
railties (>= 6.0, < 8)
|
7
6
|
|
8
7
|
GEM
|
9
8
|
remote: https://rubygems.org/
|
@@ -27,32 +26,42 @@ GEM
|
|
27
26
|
minitest (>= 5.1)
|
28
27
|
tzinfo (~> 2.0)
|
29
28
|
ast (2.4.2)
|
29
|
+
backport (1.2.0)
|
30
|
+
benchmark (0.3.0)
|
30
31
|
builder (3.2.4)
|
31
32
|
concurrent-ruby (1.2.0)
|
32
33
|
crass (1.0.6)
|
33
34
|
debug (1.7.1)
|
34
35
|
irb (>= 1.5.0)
|
35
36
|
reline (>= 0.3.1)
|
36
|
-
diff-lcs (1.5.
|
37
|
+
diff-lcs (1.5.1)
|
38
|
+
e2mmap (0.1.0)
|
37
39
|
erubi (1.12.0)
|
38
40
|
i18n (1.12.0)
|
39
41
|
concurrent-ruby (~> 1.0)
|
40
42
|
io-console (0.6.0)
|
41
43
|
irb (1.6.2)
|
42
44
|
reline (>= 0.3.0)
|
43
|
-
|
45
|
+
jaro_winkler (1.5.6)
|
46
|
+
json (2.7.1)
|
47
|
+
kramdown (2.4.0)
|
48
|
+
rexml
|
49
|
+
kramdown-parser-gfm (1.1.0)
|
50
|
+
kramdown (~> 2.0)
|
51
|
+
language_server-protocol (3.17.0.3)
|
44
52
|
loofah (2.19.1)
|
45
53
|
crass (~> 1.0.2)
|
46
54
|
nokogiri (>= 1.5.9)
|
47
55
|
method_source (1.0.0)
|
56
|
+
mini_portile2 (2.8.5)
|
48
57
|
minitest (5.17.0)
|
49
|
-
nokogiri (1.14.1
|
58
|
+
nokogiri (1.14.1)
|
59
|
+
mini_portile2 (~> 2.8.0)
|
50
60
|
racc (~> 1.4)
|
51
|
-
|
52
|
-
|
53
|
-
parallel (1.22.1)
|
54
|
-
parser (3.2.0.0)
|
61
|
+
parallel (1.24.0)
|
62
|
+
parser (3.3.0.5)
|
55
63
|
ast (~> 2.4.1)
|
64
|
+
racc
|
56
65
|
racc (1.6.2)
|
57
66
|
rack (2.2.6.2)
|
58
67
|
rack-test (2.0.2)
|
@@ -70,60 +79,90 @@ GEM
|
|
70
79
|
thor (~> 1.0)
|
71
80
|
zeitwerk (~> 2.5)
|
72
81
|
rainbow (3.1.1)
|
73
|
-
rake (13.0
|
74
|
-
|
82
|
+
rake (13.1.0)
|
83
|
+
rbs (2.8.4)
|
84
|
+
regexp_parser (2.9.0)
|
75
85
|
reline (0.3.2)
|
76
86
|
io-console (~> 0.5)
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
rspec-
|
82
|
-
|
83
|
-
rspec-
|
84
|
-
rspec-
|
87
|
+
reverse_markdown (2.1.1)
|
88
|
+
nokogiri
|
89
|
+
rexml (3.2.6)
|
90
|
+
rspec (3.13.0)
|
91
|
+
rspec-core (~> 3.13.0)
|
92
|
+
rspec-expectations (~> 3.13.0)
|
93
|
+
rspec-mocks (~> 3.13.0)
|
94
|
+
rspec-core (3.13.0)
|
95
|
+
rspec-support (~> 3.13.0)
|
96
|
+
rspec-expectations (3.13.0)
|
85
97
|
diff-lcs (>= 1.2.0, < 2.0)
|
86
|
-
rspec-support (~> 3.
|
87
|
-
rspec-mocks (3.
|
98
|
+
rspec-support (~> 3.13.0)
|
99
|
+
rspec-mocks (3.13.0)
|
88
100
|
diff-lcs (>= 1.2.0, < 2.0)
|
89
|
-
rspec-support (~> 3.
|
90
|
-
rspec-support (3.
|
91
|
-
rubocop (1.
|
101
|
+
rspec-support (~> 3.13.0)
|
102
|
+
rspec-support (3.13.0)
|
103
|
+
rubocop (1.60.2)
|
92
104
|
json (~> 2.3)
|
105
|
+
language_server-protocol (>= 3.17.0)
|
93
106
|
parallel (~> 1.10)
|
94
|
-
parser (>= 3.
|
107
|
+
parser (>= 3.3.0.2)
|
95
108
|
rainbow (>= 2.2.2, < 4.0)
|
96
109
|
regexp_parser (>= 1.8, < 3.0)
|
97
110
|
rexml (>= 3.2.5, < 4.0)
|
98
|
-
rubocop-ast (>= 1.
|
111
|
+
rubocop-ast (>= 1.30.0, < 2.0)
|
99
112
|
ruby-progressbar (~> 1.7)
|
100
|
-
unicode-display_width (>=
|
101
|
-
rubocop-ast (1.
|
102
|
-
parser (>= 3.
|
103
|
-
rubocop-capybara (2.
|
113
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
114
|
+
rubocop-ast (1.30.0)
|
115
|
+
parser (>= 3.2.1.0)
|
116
|
+
rubocop-capybara (2.20.0)
|
117
|
+
rubocop (~> 1.41)
|
118
|
+
rubocop-factory_bot (2.25.1)
|
104
119
|
rubocop (~> 1.41)
|
105
|
-
rubocop-rspec (2.
|
106
|
-
rubocop (~> 1.
|
120
|
+
rubocop-rspec (2.26.1)
|
121
|
+
rubocop (~> 1.40)
|
107
122
|
rubocop-capybara (~> 2.17)
|
108
|
-
|
123
|
+
rubocop-factory_bot (~> 2.22)
|
124
|
+
rubocop-rubycw (0.1.6)
|
125
|
+
rubocop (~> 1.0)
|
126
|
+
ruby-progressbar (1.13.0)
|
127
|
+
solargraph (0.50.0)
|
128
|
+
backport (~> 1.2)
|
129
|
+
benchmark
|
130
|
+
bundler (~> 2.0)
|
131
|
+
diff-lcs (~> 1.4)
|
132
|
+
e2mmap
|
133
|
+
jaro_winkler (~> 1.5)
|
134
|
+
kramdown (~> 2.3)
|
135
|
+
kramdown-parser-gfm (~> 1.1)
|
136
|
+
parser (~> 3.0)
|
137
|
+
rbs (~> 2.0)
|
138
|
+
reverse_markdown (~> 2.0)
|
139
|
+
rubocop (~> 1.38)
|
140
|
+
thor (~> 1.0)
|
141
|
+
tilt (~> 2.0)
|
142
|
+
yard (~> 0.9, >= 0.9.24)
|
109
143
|
thor (1.2.1)
|
144
|
+
tilt (2.3.0)
|
110
145
|
tzinfo (2.0.6)
|
111
146
|
concurrent-ruby (~> 1.0)
|
112
|
-
unicode-display_width (2.
|
147
|
+
unicode-display_width (2.5.0)
|
148
|
+
yard (0.9.34)
|
113
149
|
zeitwerk (2.6.6)
|
114
150
|
|
115
151
|
PLATFORMS
|
152
|
+
arm64-darwin-23
|
116
153
|
x86_64-darwin-21
|
117
154
|
x86_64-darwin-22
|
118
155
|
x86_64-linux
|
119
156
|
|
120
157
|
DEPENDENCIES
|
121
|
-
debug (
|
158
|
+
debug (>= 1.0.0)
|
122
159
|
minivite_rails!
|
123
|
-
rake (~> 13.
|
124
|
-
rspec (~> 3.
|
125
|
-
rubocop (~> 1.
|
126
|
-
rubocop-rspec (~> 2.
|
160
|
+
rake (~> 13.1)
|
161
|
+
rspec (~> 3.13)
|
162
|
+
rubocop (~> 1.60)
|
163
|
+
rubocop-rspec (~> 2.26)
|
164
|
+
rubocop-rubycw
|
165
|
+
solargraph
|
127
166
|
|
128
167
|
BUNDLED WITH
|
129
168
|
2.4.6
|
data/README.md
CHANGED
@@ -51,8 +51,8 @@ MiniviteRails.configuration do |c|
|
|
51
51
|
# Vite public directory, default will be `public`
|
52
52
|
# c.public_dir, default: 'public'
|
53
53
|
|
54
|
-
# Vite manifest file path, default will be `#{c.public_dir}#{c.public_base_path}/manifest.json`
|
55
|
-
# c.manifest_path = "#{c.public_dir}#{c.public_base_path}/manifest.json"
|
54
|
+
# Vite manifest file path, default will be `#{c.public_dir}#{c.public_base_path}/.vite/manifest.json`
|
55
|
+
# c.manifest_path = "#{c.public_dir}#{c.public_base_path}/.vite/manifest.json"
|
56
56
|
end
|
57
57
|
```
|
58
58
|
|
@@ -90,7 +90,7 @@ Use the following helpers in your Rails views to resolve paths to assets which a
|
|
90
90
|
|
91
91
|
### `vite_javascript_tag`
|
92
92
|
|
93
|
-
Renders a `<script>` tag for the specified Vite js entrypoints. This is the most commonly used helper and will also load needed css entrypoints.
|
93
|
+
Renders a `<script>` tag for the specified Vite js entrypoints. This is the most commonly used helper and will also load needed css entrypoints. The entry path must be relative to the root path of Vite project.
|
94
94
|
|
95
95
|
```erb
|
96
96
|
<%= vite_javascript_tag 'src/main.js' %>
|
@@ -136,6 +136,14 @@ Render a path to a specified asset built by Vite
|
|
136
136
|
|
137
137
|
Same as `vite_asset_path` but returns a full URL
|
138
138
|
|
139
|
+
### `vite_public_asset_path`
|
140
|
+
|
141
|
+
Render a path to a public asset copied by Vite
|
142
|
+
|
143
|
+
```erb
|
144
|
+
<%= vite_public_asset_path 'logo.svg' %>
|
145
|
+
```
|
146
|
+
|
139
147
|
### `vite_image_tag`
|
140
148
|
|
141
149
|
Renders an `<img>` tag for the specified Vite image asset
|
@@ -171,7 +179,7 @@ import react from '@vitejs/plugin-react'
|
|
171
179
|
|
172
180
|
// https://vitejs.dev/config/
|
173
181
|
export default defineConfig({
|
174
|
-
base: '/
|
182
|
+
base: '/vite_admin/',
|
175
183
|
plugins: [react()],
|
176
184
|
build: {
|
177
185
|
manifest: true, // This is required
|
data/Rakefile
CHANGED
@@ -16,13 +16,12 @@ module MiniviteRails
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
define_method("#{prop}="
|
19
|
+
define_method(:"#{prop}=") do |v|
|
20
20
|
@config[prop] = v
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
# Private
|
26
25
|
config_attr :id, default: ROOT_DEFAULT_ID
|
27
26
|
config_attr :cache, default: false
|
28
27
|
# The base directory of the frontend.
|
@@ -51,24 +50,24 @@ module MiniviteRails
|
|
51
50
|
@children.each_value(&:reload_manifest)
|
52
51
|
end
|
53
52
|
|
54
|
-
def add(
|
53
|
+
def add(child_id)
|
55
54
|
raise Error, 'Can only define sub configuration from root config' unless root?
|
56
|
-
raise Error, 'Id already used by root configuration' if
|
55
|
+
raise Error, 'Id already used by root configuration' if child_id == id
|
57
56
|
|
58
|
-
@children[
|
57
|
+
@children[child_id] ||= self.class.new.tap do |c|
|
59
58
|
c.instance_variable_set(:@parent, self)
|
60
59
|
c.instance_variable_set(:@children, nil)
|
61
|
-
c.id =
|
60
|
+
c.id = child_id
|
62
61
|
yield c if block_given?
|
63
62
|
end
|
64
63
|
end
|
65
64
|
|
66
|
-
def child_by_id(
|
65
|
+
def child_by_id(child_id)
|
67
66
|
raise Error, 'Can only get sub configuration from root config' unless root?
|
68
67
|
|
69
|
-
return self if
|
68
|
+
return self if child_id == id # return itself if id is root id
|
70
69
|
|
71
|
-
@children.fetch(
|
70
|
+
@children.fetch(child_id)
|
72
71
|
rescue KeyError
|
73
72
|
raise Error, "No sub configuration with id #{id}"
|
74
73
|
end
|
@@ -21,7 +21,7 @@ module MiniviteRails
|
|
21
21
|
|
22
22
|
def update_config(config)
|
23
23
|
@config = config
|
24
|
-
@manifest_path = config.manifest_path || File.join(config.public_asset_dir, 'manifest.json')
|
24
|
+
@manifest_path = config.manifest_path || File.join(config.public_asset_dir, '.vite', 'manifest.json')
|
25
25
|
@data = nil
|
26
26
|
end
|
27
27
|
|
@@ -35,6 +35,12 @@ module MiniviteRails
|
|
35
35
|
lookup!(name, **options).fetch('file')
|
36
36
|
end
|
37
37
|
|
38
|
+
def public_path_for(name)
|
39
|
+
return prefix_vite_asset(name) if dev_server_available?
|
40
|
+
|
41
|
+
File.join(config.public_base_path, name)
|
42
|
+
end
|
43
|
+
|
38
44
|
def vite_client_src
|
39
45
|
prefix_vite_asset('@vite/client') if dev_server_available?
|
40
46
|
end
|
@@ -51,20 +57,30 @@ module MiniviteRails
|
|
51
57
|
}
|
52
58
|
end
|
53
59
|
|
60
|
+
# Public: The content of the preamble needed by the React Refresh plugin.
|
54
61
|
def react_refresh_preamble
|
55
|
-
return unless
|
62
|
+
return unless dev_server_running?
|
56
63
|
|
57
64
|
<<~REACT_REFRESH
|
58
65
|
<script type="module">
|
59
|
-
|
60
|
-
RefreshRuntime.injectIntoGlobalHook(window)
|
61
|
-
window.$RefreshReg$ = () => {}
|
62
|
-
window.$RefreshSig$ = () => (type) => type
|
63
|
-
window.__vite_plugin_react_preamble_installed__ = true
|
66
|
+
#{react_preamble_code}
|
64
67
|
</script>
|
65
68
|
REACT_REFRESH
|
66
69
|
end
|
67
70
|
|
71
|
+
# Public: Source script for the React Refresh plugin.
|
72
|
+
def react_preamble_code
|
73
|
+
return unless dev_server_available?
|
74
|
+
|
75
|
+
<<~REACT_PREAMBLE_CODE
|
76
|
+
import RefreshRuntime from '#{prefix_vite_asset('@react-refresh')}'
|
77
|
+
RefreshRuntime.injectIntoGlobalHook(window)
|
78
|
+
window.$RefreshReg$ = () => {}
|
79
|
+
window.$RefreshSig$ = () => (type) => type
|
80
|
+
window.__vite_plugin_react_preamble_installed__ = true
|
81
|
+
REACT_PREAMBLE_CODE
|
82
|
+
end
|
83
|
+
|
68
84
|
protected
|
69
85
|
|
70
86
|
def dev_server_available?
|
@@ -113,40 +129,28 @@ module MiniviteRails
|
|
113
129
|
# manifest.lookup('calendar.js')
|
114
130
|
# => { "file" => "/vite/assets/calendar-1016838bab065ae1e122.js", "imports" => [] }
|
115
131
|
def lookup(name, **options)
|
116
|
-
find_manifest_entry
|
132
|
+
find_manifest_entry(resolve_entry_name(name, **options))
|
117
133
|
end
|
118
134
|
|
119
135
|
def find_manifest_entry(name)
|
120
|
-
|
121
|
-
|
122
|
-
else
|
123
|
-
data[name]
|
124
|
-
end
|
136
|
+
# If dev server is available, we don't need to get manifest entry from the manifest
|
137
|
+
dev_server_available? ? { 'file' => prefix_vite_asset(name) } : data[name]
|
125
138
|
end
|
126
139
|
|
127
140
|
def resolve_entry_name(name, type: nil)
|
128
|
-
return resolve_virtual_entry(name) if type == :virtual
|
129
|
-
|
130
141
|
name = with_file_extension(name.to_s, type)
|
131
|
-
|
142
|
+
if name =~ %r{\A(\.|~|/).+}
|
143
|
+
raise ArgumentError, "Asset names must be direct path from the project root. Found: #{name}"
|
144
|
+
end
|
132
145
|
|
133
|
-
# Explicit path, relative to the source_code_dir.
|
134
|
-
name.sub(%r{^~/(.+)$}) { return Regexp.last_match(1) }
|
135
146
|
name
|
136
147
|
end
|
137
148
|
|
138
|
-
# Internal: Resolves a virtual entry by walking all the manifest keys.
|
139
|
-
def resolve_virtual_entry(name)
|
140
|
-
data.keys.find { |file| file.include?(name) } || name
|
141
|
-
end
|
142
|
-
|
143
149
|
# Internal: Adds a file extension to the file name, unless it already has one.
|
144
150
|
def with_file_extension(name, entry_type)
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
name
|
149
|
-
end
|
151
|
+
return name unless File.extname(name).empty?
|
152
|
+
|
153
|
+
"#{name}.#{extension_for_type(entry_type)}"
|
150
154
|
end
|
151
155
|
|
152
156
|
# Internal: Allows to receive :javascript and :stylesheet as :type in helpers.
|
@@ -9,16 +9,21 @@ module MiniviteRails
|
|
9
9
|
# Public: Allows to render HTML tags for scripts and styles processed by Vite.
|
10
10
|
module TagHelpers
|
11
11
|
# Public: Renders a script tag for vite/client to enable HMR in development.
|
12
|
-
def vite_client_tag(id: nil, **options)
|
13
|
-
src = vite_manifest(id:
|
12
|
+
def vite_client_tag(id: nil, crossorigin: 'anonymous', **options)
|
13
|
+
src = vite_manifest(id:).vite_client_src
|
14
14
|
return unless src
|
15
15
|
|
16
|
-
javascript_include_tag(src, type: 'module', extname: false, **options)
|
16
|
+
javascript_include_tag(src, type: 'module', extname: false, crossorigin:, **options)
|
17
17
|
end
|
18
18
|
|
19
19
|
# Public: Renders a script tag to enable HMR with React Refresh.
|
20
|
-
def vite_react_refresh_tag(id: nil)
|
21
|
-
vite_manifest(id:
|
20
|
+
def vite_react_refresh_tag(id: nil, **options)
|
21
|
+
react_preamble_code = vite_manifest(id:).react_preamble_code
|
22
|
+
return unless react_preamble_code
|
23
|
+
|
24
|
+
options[:nonce] = true if Rails::VERSION::MAJOR >= 6 && !options.key?(:nonce)
|
25
|
+
|
26
|
+
javascript_tag(react_preamble_code.html_safe, type: :module, **options)
|
22
27
|
end
|
23
28
|
|
24
29
|
# Public: Resolves the path for the specified Vite asset.
|
@@ -26,7 +31,7 @@ module MiniviteRails
|
|
26
31
|
# Example:
|
27
32
|
# <%= vite_asset_path 'calendar.css' %> # => "/vite/assets/calendar-1016838bab065ae1e122.css"
|
28
33
|
def vite_asset_path(name, id: nil, **options)
|
29
|
-
path_to_asset vite_manifest(id:
|
34
|
+
path_to_asset vite_manifest(id:).path_for(name, **options)
|
30
35
|
end
|
31
36
|
|
32
37
|
# Public: Resolves the url for the specified Vite asset.
|
@@ -34,7 +39,15 @@ module MiniviteRails
|
|
34
39
|
# Example:
|
35
40
|
# <%= vite_asset_url 'calendar.css' %> # => "https://example.com/vite/assets/calendar-1016838bab065ae1e122.css"
|
36
41
|
def vite_asset_url(name, id: nil, **options)
|
37
|
-
url_to_asset vite_manifest(id:
|
42
|
+
url_to_asset vite_manifest(id:).path_for(name, **options)
|
43
|
+
end
|
44
|
+
|
45
|
+
# Public: Resolves the path for Vite's public assets
|
46
|
+
#
|
47
|
+
# Example:
|
48
|
+
# <%= vite_public_asset_path 'logo.svg' %> # => "/vite/logo.svg"
|
49
|
+
def vite_public_asset_path(name, id: nil)
|
50
|
+
path_to_asset vite_manifest(id:).public_path_for(name)
|
38
51
|
end
|
39
52
|
|
40
53
|
# Public: Renders a <script> tag for the specified Vite entrypoints.
|
@@ -47,26 +60,26 @@ module MiniviteRails
|
|
47
60
|
crossorigin: 'anonymous',
|
48
61
|
media: 'screen',
|
49
62
|
**options)
|
50
|
-
entries = vite_manifest(id:
|
51
|
-
tags = javascript_include_tag(*entries.fetch(:scripts), crossorigin
|
63
|
+
entries = vite_manifest(id:).resolve_entries(*names, type: asset_type)
|
64
|
+
tags = javascript_include_tag(*entries.fetch(:scripts), crossorigin:, type:, extname: false,
|
52
65
|
**options)
|
53
|
-
tags << vite_preload_tag(*entries.fetch(:imports), crossorigin
|
66
|
+
tags << vite_preload_tag(*entries.fetch(:imports), crossorigin:, **options) unless skip_preload_tags
|
54
67
|
|
55
68
|
options[:extname] = false if Rails::VERSION::MAJOR >= 7
|
56
69
|
|
57
|
-
tags << stylesheet_link_tag(*entries.fetch(:stylesheets), media
|
70
|
+
tags << stylesheet_link_tag(*entries.fetch(:stylesheets), media:, **options) unless skip_style_tags
|
58
71
|
|
59
72
|
tags
|
60
73
|
end
|
61
74
|
|
62
75
|
# Public: Renders a <script> tag for the specified Vite entrypoints.
|
63
76
|
def vite_typescript_tag(*names, id: nil, **options)
|
64
|
-
vite_javascript_tag(*names, id
|
77
|
+
vite_javascript_tag(*names, id:, asset_type: :typescript, **options)
|
65
78
|
end
|
66
79
|
|
67
80
|
# Public: Renders a <link> tag for the specified Vite entrypoints.
|
68
81
|
def vite_stylesheet_tag(*names, id: nil, **options)
|
69
|
-
style_paths = names.map { |name| vite_asset_path(name, id
|
82
|
+
style_paths = names.map { |name| vite_asset_path(name, id:, type: :stylesheet) }
|
70
83
|
|
71
84
|
options[:extname] = false if Rails::VERSION::MAJOR >= 7
|
72
85
|
|
@@ -77,27 +90,31 @@ module MiniviteRails
|
|
77
90
|
def vite_image_tag(name, id: nil, **options)
|
78
91
|
if options[:srcset] && !options[:srcset].is_a?(String)
|
79
92
|
options[:srcset] = options[:srcset].map do |src_name, size|
|
80
|
-
"#{vite_asset_path(src_name, id:
|
93
|
+
"#{vite_asset_path(src_name, id:)} #{size}"
|
81
94
|
end.join(', ')
|
82
95
|
end
|
83
96
|
|
84
|
-
image_tag(vite_asset_path(name, id:
|
97
|
+
image_tag(vite_asset_path(name, id:), options)
|
85
98
|
end
|
86
99
|
|
87
100
|
private
|
88
101
|
|
89
102
|
# Internal: Returns the current manifest loaded by Vite Ruby.
|
90
103
|
def vite_manifest(id: nil)
|
91
|
-
MiniviteRails.manifest(id:
|
104
|
+
MiniviteRails.manifest(id:)
|
92
105
|
end
|
93
106
|
|
94
107
|
# Internal: Renders a modulepreload link tag.
|
95
108
|
def vite_preload_tag(*sources, crossorigin:, **options)
|
96
|
-
sources.map
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
109
|
+
asset_paths = sources.map { |source| path_to_asset(source) }
|
110
|
+
try(:request).try(
|
111
|
+
:send_early_hints,
|
112
|
+
'Link' => asset_paths.map do |href|
|
113
|
+
%(<#{href}>; rel=modulepreload; as=script; crossorigin=#{crossorigin})
|
114
|
+
end.join("\n")
|
115
|
+
)
|
116
|
+
asset_paths.map do |href|
|
117
|
+
tag.link(rel: 'modulepreload', href:, as: 'script', crossorigin:, **options)
|
101
118
|
end.join("\n").html_safe
|
102
119
|
end
|
103
120
|
end
|
metadata
CHANGED
@@ -1,122 +1,46 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: minivite_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Linh Tran
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-02-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: actionview
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ">="
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: 6.0.0
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ">="
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: 6.0.0
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: railties
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
30
16
|
requirements:
|
31
17
|
- - ">="
|
32
18
|
- !ruby/object:Gem::Version
|
33
|
-
version: 6.0
|
19
|
+
version: '6.0'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '8'
|
34
23
|
type: :runtime
|
35
24
|
prerelease: false
|
36
25
|
version_requirements: !ruby/object:Gem::Requirement
|
37
26
|
requirements:
|
38
27
|
- - ">="
|
39
28
|
- !ruby/object:Gem::Version
|
40
|
-
version: 6.0
|
41
|
-
-
|
42
|
-
name: debug
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - "~>"
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '1.0'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - "~>"
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '1.0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: rake
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - "~>"
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '13.0'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - "~>"
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '13.0'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: rspec
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - "~>"
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '3.0'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - "~>"
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '3.0'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: rubocop
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - "~>"
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '1.21'
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - "~>"
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '1.21'
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: rubocop-rspec
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - "~>"
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: '2.18'
|
104
|
-
type: :development
|
105
|
-
prerelease: false
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - "~>"
|
29
|
+
version: '6.0'
|
30
|
+
- - "<"
|
109
31
|
- !ruby/object:Gem::Version
|
110
|
-
version: '
|
111
|
-
description:
|
32
|
+
version: '8'
|
33
|
+
description: Provides a minimalistic way to use Vite.js with Rails.
|
112
34
|
email:
|
113
35
|
- linh.mtran168@live.com
|
114
36
|
executables: []
|
115
37
|
extensions: []
|
116
38
|
extra_rdoc_files: []
|
117
39
|
files:
|
40
|
+
- ".editorconfig"
|
118
41
|
- ".rspec"
|
119
42
|
- ".rubocop.yml"
|
43
|
+
- ".ruby-version"
|
120
44
|
- ".vscode/settings.json"
|
121
45
|
- Gemfile
|
122
46
|
- Gemfile.lock
|
@@ -142,14 +66,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
142
66
|
requirements:
|
143
67
|
- - ">="
|
144
68
|
- !ruby/object:Gem::Version
|
145
|
-
version: '3.
|
69
|
+
version: '3.1'
|
146
70
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
147
71
|
requirements:
|
148
72
|
- - ">="
|
149
73
|
- !ruby/object:Gem::Version
|
150
74
|
version: '0'
|
151
75
|
requirements: []
|
152
|
-
rubygems_version: 3.
|
76
|
+
rubygems_version: 3.5.3
|
153
77
|
signing_key:
|
154
78
|
specification_version: 4
|
155
79
|
summary: Minivite Ruby Gem
|