svelte-on-rails 0.0.10 → 0.0.13
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/README.md +26 -12
- data/lib/svelte_on_rails/render_server_side.rb +5 -2
- data/lib/svelte_on_rails/view_helpers.rb +1 -1
- data/lib/tasks/svelte_on_rails_tasks.rake +6 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 60ac9b6c78cf973e7bddd6802c58dc779388e97572087c084870183c773ccf04
|
4
|
+
data.tar.gz: '0529bd1129620c1e5693ca65fbf287e95b055741f5dcc05452645baa3422649d'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 109e692e90567fe73e364229dfd1f8553914a85b486f5aa6a80ef6ff43a976533bd84ab730f3cf499bc820a9699c3daf1a48e49e38d188d7c85b3c2279952700
|
7
|
+
data.tar.gz: bc18dd1cc2093a37cd3fa747c25d3ae5ff361f47b4483b5cee991804b3a6f95b2fd2dc4f64311e05cf839cff2cb6afdecfd80e8b691a0132e124debb0b1c10a1
|
data/README.md
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Seamless and robust Svelte in Rails integration.
|
4
4
|
|
5
|
-
By default
|
5
|
+
By default, and when installed together with hotwired/turbo, it renders
|
6
6
|
svelte components on first request server side («SSR») and for subsequent
|
7
|
-
requests it provides a empty tag that
|
7
|
+
requests it provides a empty tag that will be mounted on the frontend by the associated npm package [@csedl/svelte-on-rails](https://www.npmjs.com/package/@csedl/svelte-on-rails) on the frontend.
|
8
8
|
|
9
|
-
This way works perfectly together with turbo
|
9
|
+
This way svelte works perfectly together with turbo. You will never notice
|
10
10
|
this unpleasant «blink» on the frontend and it is maximum performance
|
11
11
|
optimized. SSR compilation is handled by rollup.
|
12
12
|
|
@@ -14,15 +14,19 @@ Server-side rendering is the bottleneck on such a pipeline.
|
|
14
14
|
Although rollup is powerful, this gem is in an early state
|
15
15
|
and there may be limitations.
|
16
16
|
|
17
|
-
|
18
|
-
Although the common-js plugin is installed, I have not tested it,
|
17
|
+
Javascript is written in ESM syntax, orientated by the functionality of vite.
|
18
|
+
Although the common-js plugin is installed, I have not tested it,
|
19
19
|
so for example `require` may not work in Svelte components.
|
20
20
|
|
21
|
+
But we have done everything we can to make your setup work smoothly.
|
22
|
+
|
21
23
|
This all is developed on Rails-7 together with `vite_rails`.
|
22
24
|
|
23
25
|
Thanks to [shakacode](https://github.com/shakacode/react_on_rails)
|
24
26
|
and [ElMassimo](https://github.com/ElMassimo) because they all helped me with theyr gems.
|
25
27
|
|
28
|
+
If you have issues, please open one and contributors are welcome!
|
29
|
+
|
26
30
|
## Requirements
|
27
31
|
|
28
32
|
- actual node installed on the server
|
@@ -58,16 +62,22 @@ On the view
|
|
58
62
|
= svelte_component("myComponent", items: ['item1', 'item2'])
|
59
63
|
```
|
60
64
|
|
61
|
-
Within the `components_folder` (configs above) a component like `myComponent.svelte`
|
65
|
+
Test: Within the `components_folder` (configs above), create a component like `myComponent.svelte`
|
62
66
|
|
63
67
|
```sveltehtml
|
64
68
|
<script>
|
65
69
|
export let items
|
70
|
+
let count = 0;
|
71
|
+
|
72
|
+
function increment() {
|
73
|
+
count += 1;
|
74
|
+
}
|
66
75
|
</script>
|
67
76
|
|
68
77
|
<h1>Greetings from svelte</h1>
|
69
78
|
|
70
79
|
<ul>
|
80
|
+
<button on:click={increment}>Increment: {count}</button>
|
71
81
|
{#each items as item}
|
72
82
|
<li>{item}</li>
|
73
83
|
{/each}
|
@@ -82,6 +92,8 @@ Within the `components_folder` (configs above) a component like `myComponent.sve
|
|
82
92
|
|
83
93
|
And you should see «Greetings from svelte» on the browser.
|
84
94
|
|
95
|
+
Click the counter button and check if the component is alive.
|
96
|
+
|
85
97
|
I inserted very detailed error messages on rails and on the
|
86
98
|
npm package, so please check the logs on your browser.
|
87
99
|
|
@@ -154,14 +166,16 @@ Example from the rails console for a medium complex component
|
|
154
166
|
- Compiled MyComponent.svelte.js: 0.411ms
|
155
167
|
- => happens only once
|
156
168
|
- Rendered MyComponent.svelte server-side: 0.518ms
|
157
|
-
- => happens on every request
|
169
|
+
- => happens on every SSR request
|
170
|
+
- Rendered MyComponent.svelte as empty element that will be mounted on the client side
|
171
|
+
- => subsequent calls
|
158
172
|
- Completed 200 OK in 521ms (Views: 520.2ms | ActiveRecord: 0.0ms (0 queries, 0 cached) | GC: 0.3ms)
|
159
173
|
|
160
|
-
Best is to work with the `render_server_side: :auto` option, which you can
|
161
|
-
set as default on the config file. Then, the server does the SSR only on
|
162
|
-
initial request and the rest happens on the frontend.
|
163
|
-
|
164
174
|
## Testing
|
165
175
|
|
166
176
|
Testings are within the gem by `rspec`. And there is a [rails project](https://gitlab.com/users/sedl/projects) with
|
167
|
-
testings (based on playwright) where the npm package and this gem is tested together.
|
177
|
+
testings (based on playwright) where the npm package and this gem is tested together.
|
178
|
+
|
179
|
+
## Licence
|
180
|
+
|
181
|
+
License is MIT
|
@@ -121,8 +121,11 @@ module SvelteOnRails
|
|
121
121
|
end
|
122
122
|
|
123
123
|
def self.file_exist_case_sensitive?(containing_dir, filename)
|
124
|
-
#
|
125
|
-
|
124
|
+
# Combine the directory path and filename
|
125
|
+
full_path = File.join(containing_dir, filename)
|
126
|
+
|
127
|
+
# Check if the file exists and the path matches case-sensitively
|
128
|
+
File.exist?(full_path) && Dir[File.join(containing_dir, "*")].any? { |f| f == full_path }
|
126
129
|
end
|
127
130
|
|
128
131
|
|
@@ -30,12 +30,16 @@ namespace :svelte_on_rails do
|
|
30
30
|
|
31
31
|
development:
|
32
32
|
watch_changes: true
|
33
|
-
#
|
33
|
+
# Check on every request if any file within the svelte components folder have changed, for recompiling
|
34
|
+
# Case sensitive path checking, even the file system is case insensitive
|
35
|
+
# Make sure this ist set to tue for development and test, but not for production
|
34
36
|
|
35
37
|
test:
|
38
|
+
watch_changes: true
|
39
|
+
|
36
40
|
production:
|
37
41
|
YAML
|
38
|
-
puts "Created configuration file at
|
42
|
+
puts "Created configuration file at file://#{config_path}"
|
39
43
|
end
|
40
44
|
end
|
41
45
|
end
|