vite_ruby 3.3.0 → 4.0.0.alpha1
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/CHANGELOG.md +2 -253
- data/README.md +1 -1
- data/default.vite.json +1 -5
- data/exe/vite +0 -2
- data/lib/tasks/vite.rake +10 -48
- data/lib/vite_ruby/build.rb +16 -46
- data/lib/vite_ruby/builder.rb +26 -21
- data/lib/vite_ruby/cli/build.rb +0 -2
- data/lib/vite_ruby/cli/install.rb +9 -2
- data/lib/vite_ruby/cli/vite.rb +3 -7
- data/lib/vite_ruby/cli.rb +0 -13
- data/lib/vite_ruby/commands.rb +3 -13
- data/lib/vite_ruby/compatibility_check.rb +1 -1
- data/lib/vite_ruby/config.rb +4 -19
- data/lib/vite_ruby/dev_server_proxy.rb +5 -10
- data/lib/vite_ruby/io.rb +1 -1
- data/lib/vite_ruby/manifest.rb +11 -14
- data/lib/vite_ruby/missing_entrypoint_error.rb +7 -15
- data/lib/vite_ruby/runner.rb +5 -11
- data/lib/vite_ruby/version.rb +3 -3
- data/lib/vite_ruby.rb +5 -17
- metadata +12 -19
- data/lib/vite_ruby/cli/ssr.rb +0 -27
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3e369fc30038cbf7475208298ccc3eebbcec6ad98100b785d6303b766afc3aad
|
|
4
|
+
data.tar.gz: '0811dc3a900d49b9b0b3c406b32b96e852d5a367dce1c96924b6b0a936fddc39'
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ef190e8c53cf93255f56a69fa7db7fe684f1fc4924b21aca81d9d2160ec117accf643771a5692bf58225884958fa06fc3b1e713241eaa6f2f223b8fca35e216a
|
|
7
|
+
data.tar.gz: 22b63dc5256c147ddf084f0324f2e6a236b86b654e6cd63e99da2608c6869290aa80885b8d9c61f8c7056df449464cb24831717de5e1a0857b5cf28af303700c
|
data/CHANGELOG.md
CHANGED
|
@@ -1,260 +1,9 @@
|
|
|
1
|
-
# [
|
|
1
|
+
# [](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@3.0.8...vite_ruby@) (2022-01-18)
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
### Features
|
|
5
5
|
|
|
6
|
-
* add support for
|
|
7
|
-
* change defaults to vite@4.2.0 and vite-plugin-ruby@3.2.0 ([e9f5702](https://github.com/ElMassimo/vite_ruby/commit/e9f570294c34682a6dd18fdc2ef13675f33375e6))
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
## [3.2.15](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@3.2.14...vite_ruby@3.2.15) (2023-03-01)
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
### Features
|
|
15
|
-
|
|
16
|
-
* install dependencies with yarn if npx is not available ([#343](https://github.com/ElMassimo/vite_ruby/issues/343)) ([90c5db2](https://github.com/ElMassimo/vite_ruby/commit/90c5db2e45ed89aedfa02f0f167925e4ccb02d6d)), closes [#342](https://github.com/ElMassimo/vite_ruby/issues/342)
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
## [3.2.14](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@3.2.13...vite_ruby@3.2.14) (2022-12-22)
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
## [3.2.13](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@3.2.12...vite_ruby@3.2.13) (2022-12-09)
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
### Features
|
|
28
|
-
|
|
29
|
-
* install vite 4 by default ([c1a2e16](https://github.com/ElMassimo/vite_ruby/commit/c1a2e16a5b47225c53ad73b4f6371f2108881850))
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
## [3.2.12](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@3.2.11...vite_ruby@3.2.12) (2022-12-02)
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
### Features
|
|
37
|
-
|
|
38
|
-
* add experimental `skipProxy` setting ([#315](https://github.com/ElMassimo/vite_ruby/issues/315)) ([e9285f6](https://github.com/ElMassimo/vite_ruby/commit/e9285f62c76cc0cbbc5dc99d977e8aef30d08b6f))
|
|
39
|
-
* add ViteRuby.instance.configure API to be used in config/vite.rb ([b5b8681](https://github.com/ElMassimo/vite_ruby/commit/b5b8681f85f5388a56d72c9b05dbfc95d5ba607b))
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
### Performance Improvements
|
|
43
|
-
|
|
44
|
-
* avoid calculating digest on each lookup ([#314](https://github.com/ElMassimo/vite_ruby/issues/314)) ([62df93a](https://github.com/ElMassimo/vite_ruby/commit/62df93a15c09c652a8b7496e26cf85d5d69acce7))
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
## [3.2.11](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@3.2.10...vite_ruby@3.2.11) (2022-11-13)
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
### Bug Fixes
|
|
52
|
-
|
|
53
|
-
* avoid removing double extension for non-preprocessor assets ([#301](https://github.com/ElMassimo/vite_ruby/issues/301)) ([2024f62](https://github.com/ElMassimo/vite_ruby/commit/2024f62af917cabcb817c32a5fbbe709d477c19f))
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
## [3.2.10](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@3.2.9...vite_ruby@3.2.10) (2022-11-03)
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
## [3.2.9](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@3.2.8...vite_ruby@3.2.9) (2022-11-02)
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
### Features
|
|
65
|
-
|
|
66
|
-
* allow different ViteRuby instances to set different env vars ([25628a7](https://github.com/ElMassimo/vite_ruby/commit/25628a752cbd4828547c1f454cc4cb2217a591e0))
|
|
67
|
-
* output exit code when vite process fails ([#294](https://github.com/ElMassimo/vite_ruby/issues/294)) ([eb8f678](https://github.com/ElMassimo/vite_ruby/commit/eb8f678248a02b693fffe5a49309984fed92a051)), closes [#292](https://github.com/ElMassimo/vite_ruby/issues/292)
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
## [3.2.8](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@3.2.7...vite_ruby@3.2.8) (2022-10-28)
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
### Features
|
|
75
|
-
|
|
76
|
-
* default to vite@3.2.0 ([2ef83a5](https://github.com/ElMassimo/vite_ruby/commit/2ef83a52148f46534c4106015f3f54ec9ee807cb))
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
## [3.2.7](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@3.2.6...vite_ruby@3.2.7) (2022-10-19)
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
### Bug Fixes
|
|
84
|
-
|
|
85
|
-
* yarn berry pnp mode support ([#278](https://github.com/ElMassimo/vite_ruby/issues/278)) ([1890447](https://github.com/ElMassimo/vite_ruby/commit/189044746e536847cb33fb471cc7c42251a61072))
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
### Features
|
|
89
|
-
|
|
90
|
-
* create vite-plugin-rails, an opinionated version of `vite-plugin-ruby` ([#282](https://github.com/ElMassimo/vite_ruby/issues/282)) ([16375fb](https://github.com/ElMassimo/vite_ruby/commit/16375fb1f6f2bf86dff935ca3aaf91c333a796ff))
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
## [3.2.6](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@3.2.5...vite_ruby@3.2.6) (2022-10-07)
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
### Features
|
|
98
|
-
|
|
99
|
-
* always trigger a build if the manifest is missing ([#275](https://github.com/ElMassimo/vite_ruby/issues/275)) ([53ffdb9](https://github.com/ElMassimo/vite_ruby/commit/53ffdb9559409cb813198b4fd8a7a5ccb0c3cd21))
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
## [3.2.5](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@3.2.4...vite_ruby@3.2.5) (2022-10-07)
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
### Features
|
|
107
|
-
|
|
108
|
-
* display last build errors in MissingEntrypointError ([#274](https://github.com/ElMassimo/vite_ruby/issues/274)) ([107c980](https://github.com/ElMassimo/vite_ruby/commit/107c980449546ef73c527b88f1db11a7201e4438))
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
## [3.2.4](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@3.2.3...vite_ruby@3.2.4) (2022-10-04)
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
### Bug Fixes
|
|
116
|
-
|
|
117
|
-
* **BREAKING CHANGE:** lookup now returns nil if auto-build fails ([#268](https://github.com/ElMassimo/vite_ruby/issues/268)) ([cf2dec1](https://github.com/ElMassimo/vite_ruby/commit/cf2dec1bfec2279179c1671e5b42479549fd11c4)), closes [#267](https://github.com/ElMassimo/vite_ruby/issues/267)
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
## [3.2.3](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@3.2.2...vite_ruby@3.2.3) (2022-08-28)
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
### Bug Fixes
|
|
125
|
-
|
|
126
|
-
* prevent yarn 2+ error in `assets:precompile` ([#241](https://github.com/ElMassimo/vite_ruby/issues/241)) ([e7e857a](https://github.com/ElMassimo/vite_ruby/commit/e7e857ac763dd053a8bda4b27d26a2090269f6d8))
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
## [3.2.2](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@3.2.1...vite_ruby@3.2.2) (2022-08-12)
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
### Features
|
|
134
|
-
|
|
135
|
-
* allow framework-specific libraries to extend the CLI ([a0ed66f](https://github.com/ElMassimo/vite_ruby/commit/a0ed66fe64fb2549cecc358ccd60c82be44255aa))
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
## [3.2.1](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@3.2.0...vite_ruby@3.2.1) (2022-08-11)
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
### Bug Fixes
|
|
143
|
-
|
|
144
|
-
* require the version after defining namespace (close [#239](https://github.com/ElMassimo/vite_ruby/issues/239)) ([7b92062](https://github.com/ElMassimo/vite_ruby/commit/7b920627f0f551166b3ab321e50b6cee746168c2))
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
# [3.2.0](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@3.1.7...vite_ruby@3.2.0) (2022-07-13)
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
### Features
|
|
152
|
-
|
|
153
|
-
* use Vite 3 as the default ([#225](https://github.com/ElMassimo/vite_ruby/issues/225)) ([8fab191](https://github.com/ElMassimo/vite_ruby/commit/8fab1912dc8c7c600854b490c09a603644714266))
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
## [3.1.7](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@3.1.6...vite_ruby@3.1.7) (2022-07-13)
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
### Bug Fixes
|
|
161
|
-
|
|
162
|
-
* npm deprecation warning on assets:precompile ([#226](https://github.com/ElMassimo/vite_ruby/issues/226)) ([e4f4b75](https://github.com/ElMassimo/vite_ruby/commit/e4f4b7540ef34296f1a8a4d8f1d2838549ee8460)), closes [#220](https://github.com/ElMassimo/vite_ruby/issues/220)
|
|
163
|
-
# [](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@3.1.6...vite_ruby@) (2022-07-01)
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
## [3.1.6](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@3.1.5...vite_ruby@3.1.6) (2022-06-02)
|
|
167
|
-
|
|
168
|
-
### Bug Fixes
|
|
169
|
-
|
|
170
|
-
* Catch npm command not found, for folks who install deps with yarn ([7a0407b3211e682bc1da40d29225af58d3396cbd](https://github.com/ElMassimo/vite_ruby/commit/7a0407b3211e682bc1da40d29225af58d3396cbd))
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
## [3.1.5](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@3.1.4...vite_ruby@3.1.5) (2022-05-30)
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
### Bug Fixes
|
|
177
|
-
|
|
178
|
-
* install dependencies without confirmation in modern versions of npm ([967fbf5](https://github.com/ElMassimo/vite_ruby/commit/967fbf52aac5e52e1a059bffda79c7472874775f)), closes [#216](https://github.com/ElMassimo/vite_ruby/issues/216)
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
## [3.1.4](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@3.1.3...vite_ruby@3.1.4) (2022-05-13)
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
### Features
|
|
186
|
-
|
|
187
|
-
* expose `ViteRuby.digest` to simplify asset versioning. ([ff92ce6](https://github.com/ElMassimo/vite_ruby/commit/ff92ce6011d857efa83987d3c20d48767111e700))
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
## [3.1.3](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@3.1.2...vite_ruby@3.1.3) (2022-05-13)
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
### Bug Fixes
|
|
195
|
-
|
|
196
|
-
* change default for ssrOutputDir so it's ignored by default ([2f93b76](https://github.com/ElMassimo/vite_ruby/commit/2f93b762b29462cc619527ed47e6fa3cf8d3c8c9))
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
## [3.1.2](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@3.1.1...vite_ruby@3.1.2) (2022-05-12)
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
### Features
|
|
204
|
-
|
|
205
|
-
* add support for SSR builds (experimental) ([#212](https://github.com/ElMassimo/vite_ruby/issues/212)) ([4d6cd2b](https://github.com/ElMassimo/vite_ruby/commit/4d6cd2b84f670b1703e3bde7033e822be97bf505))
|
|
206
|
-
* ignore any vite dirs in .gitignore installation (for ssr builds) ([fd68420](https://github.com/ElMassimo/vite_ruby/commit/fd68420dfaeb79b97f8edade5bf17bfe81fd2486))
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
## [3.1.1](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@3.1.0...vite_ruby@3.1.1) (2022-04-14)
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
### Bug Fixes
|
|
214
|
-
|
|
215
|
-
* prevent error when using a proc in asset_host (close [#202](https://github.com/ElMassimo/vite_ruby/issues/202)) ([#203](https://github.com/ElMassimo/vite_ruby/issues/203)) ([cb23a81](https://github.com/ElMassimo/vite_ruby/commit/cb23a81037651ac01d993935f68cc526ec2c844d))
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
# [3.1.0](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@3.0.11...vite_ruby@3.1.0) (2022-04-01)
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
### Features
|
|
223
|
-
|
|
224
|
-
* improve capistrano-rails integration by extending asset tasks ([#200](https://github.com/ElMassimo/vite_ruby/issues/200)) ([d5704ab](https://github.com/ElMassimo/vite_ruby/commit/d5704ab55abf27cbdb5b00841bce3136147a0200))
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
## [3.0.11](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@3.0.10...vite_ruby@3.0.11) (2022-04-01)
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
### Features
|
|
232
|
-
|
|
233
|
-
* bump the default vite version ([2cb8952](https://github.com/ElMassimo/vite_ruby/commit/2cb895246b3154322273989057bf9bdc67634bc6))
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
## [3.0.10](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@3.0.9...vite_ruby@3.0.10) (2022-03-17)
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
### Bug Fixes
|
|
241
|
-
|
|
242
|
-
* avoid proxying requests starting with @ ([93d071b](https://github.com/ElMassimo/vite_ruby/commit/93d071b2b807c2e09e24d5d7ea4228974b370960))
|
|
243
|
-
* MissingExecutableError when deploying with Capistrano (close [#192](https://github.com/ElMassimo/vite_ruby/issues/192)) ([22e1691](https://github.com/ElMassimo/vite_ruby/commit/22e1691a0685b1fdeec3904657be5e69a57e6456))
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
### Features
|
|
247
|
-
|
|
248
|
-
* bump up default vite version to 2.8.6 ([fd53030](https://github.com/ElMassimo/vite_ruby/commit/fd5303017760dc176b3fb15908f08a16a175c22f))
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
## [3.0.9](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@3.0.8...vite_ruby@3.0.9) (2022-02-09)
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
### Bug Fixes
|
|
256
|
-
|
|
257
|
-
* support older versions of npm (v6) that ship with node 12 and 14 ([0accc36](https://github.com/ElMassimo/vite_ruby/commit/0accc36e9ef82fa0923af4f94253433433c0b074))
|
|
6
|
+
* **experimental:** add support for Subresource Integrity via vite-plugin-manifest-sri ([0b3142c](https://github.com/ElMassimo/vite_ruby/commit/0b3142cd9d569a5f56821f53cdade337779bb0c1))
|
|
258
7
|
|
|
259
8
|
|
|
260
9
|
|
data/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<h1 align="center">
|
|
2
2
|
<a href="https://vite-ruby.netlify.app/">
|
|
3
|
-
<img src="https://raw.githubusercontent.com/ElMassimo/vite_ruby/main/logo.svg" width="120px"/>
|
|
3
|
+
<img src="https://raw.githubusercontent.com/ElMassimo/vite_ruby/main/docs/public/logo.svg" width="120px"/>
|
|
4
4
|
</a>
|
|
5
5
|
|
|
6
6
|
<br>
|
data/default.vite.json
CHANGED
|
@@ -11,15 +11,11 @@
|
|
|
11
11
|
"entrypointsDir": "entrypoints",
|
|
12
12
|
"sourceCodeDir": "app/frontend",
|
|
13
13
|
"skipCompatibilityCheck": false,
|
|
14
|
-
"skipProxy": false,
|
|
15
14
|
"host": "localhost",
|
|
16
15
|
"https": null,
|
|
17
16
|
"port": 3036,
|
|
18
17
|
"hideBuildConsoleOutput": false,
|
|
19
18
|
"viteBinPath": "node_modules/.bin/vite",
|
|
20
19
|
"watchAdditionalPaths": [],
|
|
21
|
-
"base": ""
|
|
22
|
-
"ssrBuildEnabled": false,
|
|
23
|
-
"ssrEntrypoint": "~/ssr/ssr.{js,ts,jsx,tsx}",
|
|
24
|
-
"ssrOutputDir": "public/vite-ssr"
|
|
20
|
+
"base": ""
|
|
25
21
|
}
|
data/exe/vite
CHANGED
data/lib/tasks/vite.rake
CHANGED
|
@@ -9,44 +9,29 @@ namespace :vite do
|
|
|
9
9
|
ViteRuby.commands.install_binstubs
|
|
10
10
|
end
|
|
11
11
|
|
|
12
|
-
desc '
|
|
12
|
+
desc 'Compile JavaScript packs using vite for production with digests'
|
|
13
13
|
task build: :'vite:verify_install' do
|
|
14
14
|
ViteRuby.commands.build_from_task
|
|
15
15
|
end
|
|
16
16
|
|
|
17
|
-
desc '
|
|
18
|
-
task build_ssr: :'vite:verify_install' do
|
|
19
|
-
ViteRuby.commands.build_from_task('--ssr')
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
desc 'Bundle entrypoints using Vite Ruby (SSR only if enabled)'
|
|
23
|
-
task build_all: :'vite:verify_install' do
|
|
24
|
-
ViteRuby.commands.build_from_task
|
|
25
|
-
ViteRuby.commands.build_from_task('--ssr') if ViteRuby.config.ssr_build_enabled
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
desc 'Remove old bundles created by ViteRuby'
|
|
17
|
+
desc 'Remove old compiled vites'
|
|
29
18
|
task :clean, [:keep, :age] => :'vite:verify_install' do |_, args|
|
|
30
19
|
ViteRuby.commands.clean_from_task(args)
|
|
31
20
|
end
|
|
32
21
|
|
|
33
|
-
desc 'Remove the build output directory
|
|
22
|
+
desc 'Remove the vite build output directory'
|
|
34
23
|
task clobber: :'vite:verify_install' do
|
|
35
24
|
ViteRuby.commands.clobber
|
|
36
25
|
end
|
|
37
26
|
|
|
38
|
-
desc '
|
|
27
|
+
desc 'Verifies if ViteRuby is properly installed in this application'
|
|
39
28
|
task :verify_install do
|
|
40
29
|
ViteRuby.commands.verify_install
|
|
41
30
|
end
|
|
42
31
|
|
|
43
|
-
desc '
|
|
32
|
+
desc 'Ensures build dependencies like Vite are installed when compiling assets'
|
|
44
33
|
task :install_dependencies do
|
|
45
|
-
|
|
46
|
-
result = system({ 'NODE_ENV' => 'development' }, cmd)
|
|
47
|
-
|
|
48
|
-
# Fallback to `yarn` if `npx` is not available.
|
|
49
|
-
system({ 'NODE_ENV' => 'development' }, 'yarn install --frozen-lockfile') if result.nil?
|
|
34
|
+
system({ 'NODE_ENV' => 'development' }, 'npx --yes ci')
|
|
50
35
|
end
|
|
51
36
|
|
|
52
37
|
desc "Provide information on ViteRuby's environment"
|
|
@@ -59,38 +44,15 @@ unless ENV['VITE_RUBY_SKIP_ASSETS_PRECOMPILE_EXTENSION'] == 'true'
|
|
|
59
44
|
if Rake::Task.task_defined?('assets:precompile')
|
|
60
45
|
Rake::Task['assets:precompile'].enhance do |task|
|
|
61
46
|
prefix = task.name.split(/#|assets:precompile/).first
|
|
62
|
-
Rake::Task["#{ prefix }vite:
|
|
63
|
-
Rake::Task["#{ prefix }vite:build_all"].invoke
|
|
47
|
+
Rake::Task["#{ prefix }vite:build"].invoke
|
|
64
48
|
end
|
|
65
49
|
else
|
|
66
|
-
Rake::Task.define_task('assets:precompile' => ['vite:install_dependencies', 'vite:
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
unless Rake::Task.task_defined?('assets:clean')
|
|
70
|
-
Rake::Task.define_task('assets:clean', [:keep, :age])
|
|
71
|
-
end
|
|
72
|
-
Rake::Task['assets:clean'].enhance do |_, args|
|
|
73
|
-
Rake::Task['vite:clean'].invoke(*args.to_h.values)
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
if Rake::Task.task_defined?('assets:clobber')
|
|
77
|
-
Rake::Task['assets:clobber'].enhance do
|
|
78
|
-
Rake::Task['vite:clobber'].invoke
|
|
79
|
-
end
|
|
80
|
-
else
|
|
81
|
-
Rake::Task.define_task('assets:clobber' => 'vite:clobber')
|
|
50
|
+
Rake::Task.define_task('assets:precompile' => ['vite:install_dependencies', 'vite:build'])
|
|
82
51
|
end
|
|
83
52
|
end
|
|
84
53
|
|
|
85
54
|
# Any prerequisite task that installs packages should also install build dependencies.
|
|
86
55
|
if ARGV.include?('assets:precompile')
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
else
|
|
90
|
-
ENV['NPM_CONFIG_INCLUDE'] = 'dev'
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
if ViteRuby.commands.legacy_yarn_version?
|
|
94
|
-
ENV['YARN_PRODUCTION'] = 'false'
|
|
95
|
-
end
|
|
56
|
+
ENV['NPM_CONFIG_PRODUCTION'] = 'false'
|
|
57
|
+
ENV['YARN_PRODUCTION'] = 'false'
|
|
96
58
|
end
|
data/lib/vite_ruby/build.rb
CHANGED
|
@@ -1,35 +1,18 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require 'json'
|
|
4
3
|
require 'time'
|
|
5
4
|
|
|
6
5
|
# Internal: Value object with information about the last build.
|
|
7
|
-
ViteRuby::Build = Struct.new(:success, :timestamp, :vite_ruby, :digest, :current_digest
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
private
|
|
19
|
-
|
|
20
|
-
# Internal: Reads metadata recorded on the last build, if it exists.
|
|
21
|
-
def parse_metadata(pathname)
|
|
22
|
-
return default_metadata unless pathname.exist?
|
|
23
|
-
|
|
24
|
-
JSON.parse(pathname.read.to_s).transform_keys(&:to_sym).slice(*members)
|
|
25
|
-
rescue JSON::JSONError, Errno::ENOENT, Errno::ENOTDIR
|
|
26
|
-
default_metadata
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
# Internal: To make it evident that there's no last build in error messages.
|
|
30
|
-
def default_metadata
|
|
31
|
-
{ timestamp: 'never', digest: 'none' }
|
|
32
|
-
end
|
|
6
|
+
ViteRuby::Build = Struct.new(:success, :timestamp, :vite_ruby, :digest, :current_digest) do
|
|
7
|
+
# Internal: Combines information from a previous build with the current digest.
|
|
8
|
+
def self.from_previous(attrs, current_digest)
|
|
9
|
+
new(
|
|
10
|
+
attrs['success'],
|
|
11
|
+
attrs['timestamp'] || 'never',
|
|
12
|
+
attrs['vite_ruby'] || 'unknown',
|
|
13
|
+
attrs['digest'] || 'none',
|
|
14
|
+
current_digest,
|
|
15
|
+
)
|
|
33
16
|
end
|
|
34
17
|
|
|
35
18
|
# Internal: A build is considered stale when watched files have changed since
|
|
@@ -53,30 +36,17 @@ ViteRuby::Build = Struct.new(:success, :timestamp, :vite_ruby, :digest, :current
|
|
|
53
36
|
end
|
|
54
37
|
|
|
55
38
|
# Internal: Returns a new build with the specified result.
|
|
56
|
-
def with_result(
|
|
39
|
+
def with_result(success)
|
|
57
40
|
self.class.new(
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
current_digest: current_digest,
|
|
63
|
-
last_build_path: last_build_path,
|
|
41
|
+
success,
|
|
42
|
+
Time.now.strftime('%F %T'),
|
|
43
|
+
ViteRuby::VERSION,
|
|
44
|
+
current_digest,
|
|
64
45
|
)
|
|
65
46
|
end
|
|
66
47
|
|
|
67
|
-
# Internal: Writes the result of the new build to a local file.
|
|
68
|
-
def write_to_cache
|
|
69
|
-
last_build_path.write to_json
|
|
70
|
-
end
|
|
71
|
-
|
|
72
48
|
# Internal: Returns a JSON string with the metadata of the build.
|
|
73
49
|
def to_json(*_args)
|
|
74
|
-
JSON.pretty_generate(
|
|
75
|
-
success: success,
|
|
76
|
-
errors: errors,
|
|
77
|
-
timestamp: timestamp,
|
|
78
|
-
vite_ruby: vite_ruby,
|
|
79
|
-
digest: digest,
|
|
80
|
-
)
|
|
50
|
+
JSON.pretty_generate(to_h)
|
|
81
51
|
end
|
|
82
52
|
end
|
data/lib/vite_ruby/builder.rb
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require 'json'
|
|
3
4
|
require 'digest/sha1'
|
|
4
5
|
|
|
5
6
|
# Public: Keeps track of watched files and triggers builds as needed.
|
|
@@ -11,13 +12,9 @@ class ViteRuby::Builder
|
|
|
11
12
|
# Public: Checks if the watched files have changed since the last compilation,
|
|
12
13
|
# and triggers a Vite build if any files have changed.
|
|
13
14
|
def build(*args)
|
|
14
|
-
last_build = last_build_metadata
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
stdout, stderr, status = build_with_vite(*args)
|
|
18
|
-
log_build_result(stdout, stderr, status)
|
|
19
|
-
record_build_metadata(last_build, errors: stderr, success: status.success?)
|
|
20
|
-
status.success?
|
|
15
|
+
last_build = last_build_metadata
|
|
16
|
+
if args.delete('--force') || last_build.stale?
|
|
17
|
+
build_with_vite(*args).tap { |success| record_build_metadata(success, last_build) }
|
|
21
18
|
elsif last_build.success
|
|
22
19
|
logger.debug "Skipping vite build. Watched files have not changed since the last build at #{ last_build.timestamp }"
|
|
23
20
|
true
|
|
@@ -28,8 +25,8 @@ class ViteRuby::Builder
|
|
|
28
25
|
end
|
|
29
26
|
|
|
30
27
|
# Internal: Reads the result of the last compilation from disk.
|
|
31
|
-
def last_build_metadata
|
|
32
|
-
ViteRuby::Build.from_previous(
|
|
28
|
+
def last_build_metadata
|
|
29
|
+
ViteRuby::Build.from_previous(last_build_attrs, watched_files_digest)
|
|
33
30
|
end
|
|
34
31
|
|
|
35
32
|
private
|
|
@@ -38,35 +35,44 @@ private
|
|
|
38
35
|
|
|
39
36
|
def_delegators :@vite_ruby, :config, :logger, :run
|
|
40
37
|
|
|
38
|
+
# Internal: Reads metadata recorded on the last build, if it exists.
|
|
39
|
+
def last_build_attrs
|
|
40
|
+
last_build_path.exist? ? JSON.parse(last_build_path.read.to_s) : {}
|
|
41
|
+
rescue JSON::JSONError, Errno::ENOENT, Errno::ENOTDIR
|
|
42
|
+
{}
|
|
43
|
+
end
|
|
44
|
+
|
|
41
45
|
# Internal: Writes a digest of the watched files to disk for future checks.
|
|
42
|
-
def record_build_metadata(
|
|
46
|
+
def record_build_metadata(success, build)
|
|
43
47
|
config.build_cache_dir.mkpath
|
|
44
|
-
build.with_result(
|
|
48
|
+
last_build_path.write build.with_result(success).to_json
|
|
45
49
|
end
|
|
46
50
|
|
|
47
51
|
# Internal: The file path where metadata of the last build is stored.
|
|
48
|
-
def last_build_path
|
|
49
|
-
config.build_cache_dir.join("last
|
|
52
|
+
def last_build_path
|
|
53
|
+
config.build_cache_dir.join("last-build-#{ config.mode }.json")
|
|
50
54
|
end
|
|
51
55
|
|
|
52
56
|
# Internal: Returns a digest of all the watched files, allowing to detect
|
|
53
57
|
# changes, and skip Vite builds if no files have changed.
|
|
54
58
|
def watched_files_digest
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
config.within_root do
|
|
59
|
+
Dir.chdir File.expand_path(config.root) do
|
|
58
60
|
files = Dir[*config.watched_paths].reject { |f| File.directory?(f) }
|
|
59
61
|
file_ids = files.sort.map { |f| "#{ File.basename(f) }/#{ Digest::SHA1.file(f).hexdigest }" }
|
|
60
|
-
|
|
61
|
-
@last_digest = Digest::SHA1.hexdigest(file_ids.join('/'))
|
|
62
|
+
Digest::SHA1.hexdigest(file_ids.join('/'))
|
|
62
63
|
end
|
|
63
64
|
end
|
|
64
65
|
|
|
65
66
|
# Public: Initiates a Vite build command to generate assets.
|
|
67
|
+
#
|
|
68
|
+
# Returns true if the build is successful, or false if it failed.
|
|
66
69
|
def build_with_vite(*args)
|
|
67
70
|
logger.info 'Building with Vite ⚡️'
|
|
68
71
|
|
|
69
|
-
run(['build', *args])
|
|
72
|
+
stdout, stderr, status = run(['build', *args])
|
|
73
|
+
log_build_result(stdout, stderr.to_s, status)
|
|
74
|
+
|
|
75
|
+
status.success?
|
|
70
76
|
end
|
|
71
77
|
|
|
72
78
|
# Internal: Outputs the build results.
|
|
@@ -75,10 +81,9 @@ private
|
|
|
75
81
|
def log_build_result(_stdout, stderr, status)
|
|
76
82
|
if status.success?
|
|
77
83
|
logger.info "Build with Vite complete: #{ config.build_output_dir }"
|
|
78
|
-
logger.error stderr unless stderr.empty?
|
|
84
|
+
logger.error stderr.to_s unless stderr.empty?
|
|
79
85
|
else
|
|
80
86
|
logger.error stderr
|
|
81
|
-
logger.error status
|
|
82
87
|
logger.error 'Build with Vite failed! ❌'
|
|
83
88
|
logger.error '❌ Check that vite and vite-plugin-ruby are in devDependencies and have been installed. ' if stderr.include?('ERR! canceled')
|
|
84
89
|
end
|
data/lib/vite_ruby/cli/build.rb
CHANGED
|
@@ -5,10 +5,8 @@ class ViteRuby::CLI::Build < ViteRuby::CLI::Vite
|
|
|
5
5
|
|
|
6
6
|
desc 'Bundle all entrypoints using Vite.'
|
|
7
7
|
shared_options
|
|
8
|
-
option(:ssr, desc: 'Build the SSR entrypoint instead', type: :boolean)
|
|
9
8
|
option(:force, desc: 'Force the build even if assets have not changed', type: :boolean)
|
|
10
9
|
option(:watch, desc: 'Start the Rollup watcher and rebuild on files changes', type: :boolean)
|
|
11
|
-
option(:profile, desc: 'Gather performance metrics from the build ', type: :boolean)
|
|
12
10
|
|
|
13
11
|
def call(**options)
|
|
14
12
|
super { |args| ViteRuby.commands.build_from_task(*args) }
|
|
@@ -91,7 +91,9 @@ private
|
|
|
91
91
|
append(gitignore_file, <<~GITIGNORE)
|
|
92
92
|
|
|
93
93
|
# Vite Ruby
|
|
94
|
-
/public/vite
|
|
94
|
+
/public/vite
|
|
95
|
+
/public/vite-dev
|
|
96
|
+
/public/vite-test
|
|
95
97
|
node_modules
|
|
96
98
|
# Vite uses dotenv and suggests to ignore local-only env files. See
|
|
97
99
|
# https://vitejs.dev/guide/env-and-mode.html#env-files
|
|
@@ -111,7 +113,7 @@ private
|
|
|
111
113
|
def run_with_capture(*args, **options)
|
|
112
114
|
Dir.chdir(root) do
|
|
113
115
|
_, stderr, status = ViteRuby::IO.capture(*args, **options)
|
|
114
|
-
say(stderr) unless status.success? || stderr.empty?
|
|
116
|
+
say(stderr) unless status.success? || stderr.to_s.empty?
|
|
115
117
|
end
|
|
116
118
|
end
|
|
117
119
|
|
|
@@ -132,3 +134,8 @@ private
|
|
|
132
134
|
$stderr = old_stderr
|
|
133
135
|
end
|
|
134
136
|
end
|
|
137
|
+
|
|
138
|
+
# NOTE: This allows framework-specific variants to extend the installation.
|
|
139
|
+
ViteRuby.framework_libraries.each do |_framework, library|
|
|
140
|
+
require "#{ library.name.tr('-', '/') }/installation"
|
|
141
|
+
end
|
data/lib/vite_ruby/cli/vite.rb
CHANGED
|
@@ -3,18 +3,14 @@
|
|
|
3
3
|
class ViteRuby::CLI::Vite < Dry::CLI::Command
|
|
4
4
|
CURRENT_ENV = ENV['RACK_ENV'] || ENV['RAILS_ENV']
|
|
5
5
|
|
|
6
|
-
def self.
|
|
6
|
+
def self.shared_options
|
|
7
7
|
option(:mode, default: self::DEFAULT_ENV, values: %w[development production test], aliases: ['m'], desc: 'The build mode for Vite')
|
|
8
|
+
option(:clobber, desc: 'Clear cache and previous builds', type: :boolean, aliases: %w[clean clear])
|
|
9
|
+
option(:debug, desc: 'Run Vite in verbose mode, printing all debugging output', aliases: ['verbose'], type: :boolean)
|
|
8
10
|
option(:inspect, desc: 'Run Vite in a debugging session with node --inspect-brk', aliases: ['inspect-brk'], type: :boolean)
|
|
9
11
|
option(:trace_deprecation, desc: 'Run Vite in debugging mode with node --trace-deprecation', aliases: ['trace-deprecation'], type: :boolean)
|
|
10
12
|
end
|
|
11
13
|
|
|
12
|
-
def self.shared_options
|
|
13
|
-
executable_options
|
|
14
|
-
option(:debug, desc: 'Run Vite in verbose mode, printing all debugging output', aliases: ['verbose'], type: :boolean)
|
|
15
|
-
option(:clobber, desc: 'Clear cache and previous builds', type: :boolean, aliases: %w[clean clear])
|
|
16
|
-
end
|
|
17
|
-
|
|
18
14
|
def call(mode:, args: [], clobber: false, **boolean_opts)
|
|
19
15
|
ViteRuby.env['VITE_RUBY_MODE'] = mode
|
|
20
16
|
ViteRuby.commands.clobber if clobber
|
data/lib/vite_ruby/cli.rb
CHANGED
|
@@ -11,20 +11,7 @@ class ViteRuby::CLI
|
|
|
11
11
|
register 'clobber', Clobber, aliases: %w[clean clear]
|
|
12
12
|
register 'dev', Dev, aliases: %w[d serve]
|
|
13
13
|
register 'install', Install
|
|
14
|
-
register 'ssr', SSR
|
|
15
14
|
register 'version', Version, aliases: ['v', '-v', '--version', 'info']
|
|
16
15
|
register 'upgrade', Upgrade, aliases: ['update']
|
|
17
16
|
register 'upgrade_packages', UpgradePackages, aliases: ['update_packages']
|
|
18
|
-
|
|
19
|
-
# Internal: Allows framework-specific variants to extend the CLI.
|
|
20
|
-
def self.require_framework_libraries(path = 'cli')
|
|
21
|
-
ViteRuby.framework_libraries.each do |_framework, library|
|
|
22
|
-
require [library.name.tr('-', '/').to_s, path].compact.join('/')
|
|
23
|
-
end
|
|
24
|
-
rescue LoadError
|
|
25
|
-
require_framework_libraries 'installation' unless path == 'installation'
|
|
26
|
-
end
|
|
27
17
|
end
|
|
28
|
-
|
|
29
|
-
# NOTE: This allows framework-specific variants to extend the CLI.
|
|
30
|
-
ViteRuby::CLI.require_framework_libraries('cli')
|
data/lib/vite_ruby/commands.rb
CHANGED
|
@@ -23,7 +23,7 @@ class ViteRuby::Commands
|
|
|
23
23
|
|
|
24
24
|
# Public: Removes all build cache and previously compiled assets.
|
|
25
25
|
def clobber
|
|
26
|
-
dirs = [config.build_output_dir, config.
|
|
26
|
+
dirs = [config.build_output_dir, config.build_cache_dir, config.vite_cache_dir]
|
|
27
27
|
dirs.each { |dir| dir.rmtree if dir.exist? }
|
|
28
28
|
$stdout.puts "Removed vite cache and output dirs:\n\t#{ dirs.join("\n\t") }"
|
|
29
29
|
end
|
|
@@ -66,16 +66,6 @@ class ViteRuby::Commands
|
|
|
66
66
|
`bundle config --delete bin`
|
|
67
67
|
end
|
|
68
68
|
|
|
69
|
-
# Internal: Checks if the npm version is 6 or lower.
|
|
70
|
-
def legacy_npm_version?
|
|
71
|
-
`npm --version`.to_i < 7 rescue false
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
# Internal: Checks if the yarn version is 1.x.
|
|
75
|
-
def legacy_yarn_version?
|
|
76
|
-
`yarn --version`.to_i < 2 rescue false
|
|
77
|
-
end
|
|
78
|
-
|
|
79
69
|
# Internal: Verifies if ViteRuby is properly installed.
|
|
80
70
|
def verify_install
|
|
81
71
|
unless File.exist?(config.root.join('bin/vite'))
|
|
@@ -100,7 +90,7 @@ class ViteRuby::Commands
|
|
|
100
90
|
|
|
101
91
|
# Internal: Prints information about ViteRuby's environment.
|
|
102
92
|
def print_info
|
|
103
|
-
config.
|
|
93
|
+
Dir.chdir(config.root) do
|
|
104
94
|
$stdout.puts "bin/vite present?: #{ File.exist? 'bin/vite' }"
|
|
105
95
|
|
|
106
96
|
$stdout.puts "vite_ruby: #{ ViteRuby::VERSION }"
|
|
@@ -143,7 +133,7 @@ private
|
|
|
143
133
|
|
|
144
134
|
def versions
|
|
145
135
|
all_files = Dir.glob("#{ config.build_output_dir }/**/*")
|
|
146
|
-
entries = all_files - config.
|
|
136
|
+
entries = all_files - [config.manifest_path] - current_version_files
|
|
147
137
|
entries.reject { |file| File.directory?(file) }
|
|
148
138
|
.group_by { |file| File.mtime(file).utc.to_i }
|
|
149
139
|
.sort.reverse
|
|
@@ -24,7 +24,7 @@ module ViteRuby::CompatibilityCheck
|
|
|
24
24
|
raise ArgumentError, <<~ERROR
|
|
25
25
|
vite-plugin-ruby@#{ npm_req } might not be compatible with vite_ruby-#{ ViteRuby::VERSION }
|
|
26
26
|
|
|
27
|
-
You may disable this check if needed: https://vite-ruby.netlify.app/config/#
|
|
27
|
+
You may disable this check if needed: https://vite-ruby.netlify.app/config/#skipCompatibilityCheck
|
|
28
28
|
|
|
29
29
|
You may upgrade both by running:
|
|
30
30
|
|
data/lib/vite_ruby/config.rb
CHANGED
|
@@ -5,10 +5,6 @@ require 'json'
|
|
|
5
5
|
# Public: Allows to resolve configuration sourced from `config/vite.json` and
|
|
6
6
|
# environment variables, combining them with the default options.
|
|
7
7
|
class ViteRuby::Config
|
|
8
|
-
def origin
|
|
9
|
-
"#{ protocol }://#{ host_with_port }"
|
|
10
|
-
end
|
|
11
|
-
|
|
12
8
|
def protocol
|
|
13
9
|
https ? 'https' : 'http'
|
|
14
10
|
end
|
|
@@ -27,11 +23,6 @@ class ViteRuby::Config
|
|
|
27
23
|
build_output_dir.join('manifest-assets.json')
|
|
28
24
|
end
|
|
29
25
|
|
|
30
|
-
# Internal: Path to the manifest files generated by Vite and vite-plugin-ruby.
|
|
31
|
-
def manifest_paths
|
|
32
|
-
[manifest_path, assets_manifest_path].select(&:exist?)
|
|
33
|
-
end
|
|
34
|
-
|
|
35
26
|
# Public: The directory where Vite will store the built assets.
|
|
36
27
|
def build_output_dir
|
|
37
28
|
root.join(public_dir, public_output_dir)
|
|
@@ -59,12 +50,12 @@ class ViteRuby::Config
|
|
|
59
50
|
end
|
|
60
51
|
|
|
61
52
|
# Public: Sets additional environment variables for vite-plugin-ruby.
|
|
62
|
-
def to_env
|
|
53
|
+
def to_env
|
|
63
54
|
CONFIGURABLE_WITH_ENV.each_with_object({}) do |option, env|
|
|
64
55
|
unless (value = @config[option]).nil?
|
|
65
56
|
env["#{ ViteRuby::ENV_PREFIX }_#{ option.upcase }"] = value.to_s
|
|
66
57
|
end
|
|
67
|
-
end.merge(
|
|
58
|
+
end.merge(ViteRuby.env)
|
|
68
59
|
end
|
|
69
60
|
|
|
70
61
|
# Internal: Files and directories that should be watched for changes.
|
|
@@ -79,11 +70,6 @@ class ViteRuby::Config
|
|
|
79
70
|
].freeze
|
|
80
71
|
end
|
|
81
72
|
|
|
82
|
-
# Internal: Changes the current directory to the root dir.
|
|
83
|
-
def within_root(&block)
|
|
84
|
-
Dir.chdir(File.expand_path(root), &block)
|
|
85
|
-
end
|
|
86
|
-
|
|
87
73
|
private
|
|
88
74
|
|
|
89
75
|
# Internal: Coerces all the configuration values, in case they were passed
|
|
@@ -93,8 +79,7 @@ private
|
|
|
93
79
|
config['port'] = config['port'].to_i
|
|
94
80
|
config['root'] = Pathname.new(config['root'])
|
|
95
81
|
config['build_cache_dir'] = config['root'].join(config['build_cache_dir'])
|
|
96
|
-
config
|
|
97
|
-
coerce_booleans(config, 'auto_build', 'hide_build_console_output', 'https', 'skip_compatibility_check', 'skip_proxy')
|
|
82
|
+
coerce_booleans(config, 'auto_build', 'hide_build_console_output', 'https', 'skip_compatibility_check')
|
|
98
83
|
end
|
|
99
84
|
|
|
100
85
|
# Internal: Coerces configuration options to boolean.
|
|
@@ -136,7 +121,7 @@ private
|
|
|
136
121
|
'config_path' => option_from_env('config_path') || DEFAULT_CONFIG.fetch('config_path'),
|
|
137
122
|
'mode' => option_from_env('mode') || mode,
|
|
138
123
|
'root' => option_from_env('root') || root,
|
|
139
|
-
}
|
|
124
|
+
}
|
|
140
125
|
end
|
|
141
126
|
|
|
142
127
|
# Internal: Used to load a JSON file from the specified path.
|
|
@@ -38,7 +38,7 @@ private
|
|
|
38
38
|
uri
|
|
39
39
|
.sub(HOST_WITH_PORT_REGEX, '/') # Hanami adds the host and port.
|
|
40
40
|
.sub('.ts.js', '.ts') # Hanami's javascript helper always adds the extension.
|
|
41
|
-
.sub(
|
|
41
|
+
.sub(/(\.(?!min|module)\w+)\.css$/, '\1') # Rails' stylesheet_link_tag always adds the extension.
|
|
42
42
|
end
|
|
43
43
|
|
|
44
44
|
def forward_to_vite_dev_server(env)
|
|
@@ -54,22 +54,17 @@ private
|
|
|
54
54
|
|
|
55
55
|
def vite_should_handle?(env)
|
|
56
56
|
path = normalize_uri(env['PATH_INFO'])
|
|
57
|
-
return true if path.start_with?(
|
|
57
|
+
return true if path.start_with?(vite_asset_url_prefix) # Vite asset
|
|
58
|
+
return true if path.start_with?(VITE_DEPENDENCY_PREFIX) # Packages and imports
|
|
58
59
|
return true if file_in_vite_root?(path) # Fallback if Vite can serve the file
|
|
59
60
|
end
|
|
60
61
|
|
|
61
|
-
# NOTE: When using an empty 'public_output_dir', we need to rely on a
|
|
62
|
-
# filesystem check to check whether Vite should serve the request.
|
|
63
62
|
def file_in_vite_root?(path)
|
|
64
63
|
path.include?('.') && # Check for extension, avoid filesystem if possible.
|
|
65
64
|
config.vite_root_dir.join(path.start_with?('/') ? path[1..-1] : path).file?
|
|
66
65
|
end
|
|
67
66
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
#
|
|
71
|
-
# If the path starts with that prefix, it will be redirected to Vite.
|
|
72
|
-
def vite_url_prefix
|
|
73
|
-
@vite_url_prefix ||= config.public_output_dir.empty? ? VITE_DEPENDENCY_PREFIX : "/#{ config.public_output_dir }/"
|
|
67
|
+
def vite_asset_url_prefix
|
|
68
|
+
@vite_asset_url_prefix ||= config.public_output_dir.empty? ? "\0" : "/#{ config.public_output_dir }/"
|
|
74
69
|
end
|
|
75
70
|
end
|
data/lib/vite_ruby/io.rb
CHANGED
data/lib/vite_ruby/manifest.rb
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
# lookup_entrypoint('calendar', type: :javascript)
|
|
8
8
|
# => { "file" => "/vite/assets/calendar-1016838bab065ae1e314.js", "imports" => [] }
|
|
9
9
|
#
|
|
10
|
-
# NOTE: Using
|
|
10
|
+
# NOTE: Using "autoBuild": true` in `config/vite.json` file will trigger a build
|
|
11
11
|
# on demand as needed, before performing any lookup.
|
|
12
12
|
class ViteRuby::Manifest
|
|
13
13
|
def initialize(vite_ruby)
|
|
@@ -22,16 +22,15 @@ class ViteRuby::Manifest
|
|
|
22
22
|
lookup!(name, **options).fetch('file')
|
|
23
23
|
end
|
|
24
24
|
|
|
25
|
-
# Public: Returns
|
|
25
|
+
# Public: Returns entries, imported modules, and stylesheets for the specified
|
|
26
26
|
# entrypoint files.
|
|
27
27
|
def resolve_entries(*names, **options)
|
|
28
28
|
entries = names.map { |name| lookup!(name, **options) }
|
|
29
|
-
script_paths = entries.map { |entry| entry.fetch('file') }
|
|
30
29
|
|
|
31
30
|
imports = dev_server_running? ? [] : entries.flat_map { |entry| entry['imports'] }.compact.uniq
|
|
32
31
|
{
|
|
33
|
-
|
|
34
|
-
imports: imports.map
|
|
32
|
+
main: entries.map(&TO_ENTRY),
|
|
33
|
+
imports: imports.map(&TO_ENTRY).uniq,
|
|
35
34
|
stylesheets: dev_server_running? ? [] : (entries + imports).flat_map { |entry| entry['css'] }.compact.uniq,
|
|
36
35
|
}
|
|
37
36
|
end
|
|
@@ -63,6 +62,9 @@ class ViteRuby::Manifest
|
|
|
63
62
|
|
|
64
63
|
protected
|
|
65
64
|
|
|
65
|
+
# Internal: Returns a [src, attrs] entry.
|
|
66
|
+
TO_ENTRY = ->(entry) { [entry.fetch('file'), entry.slice('integrity').symbolize_keys] }
|
|
67
|
+
|
|
66
68
|
# Internal: Strict version of lookup.
|
|
67
69
|
#
|
|
68
70
|
# Returns a relative path for the asset, or raises an error if not found.
|
|
@@ -78,7 +80,7 @@ protected
|
|
|
78
80
|
# manifest.lookup('calendar.js')
|
|
79
81
|
# => { "file" => "/vite/assets/calendar-1016838bab065ae1e122.js", "imports" => [] }
|
|
80
82
|
def lookup(name, **options)
|
|
81
|
-
@build_mutex.synchronize { builder.build
|
|
83
|
+
@build_mutex.synchronize { builder.build } if should_build?
|
|
82
84
|
|
|
83
85
|
find_manifest_entry resolve_entry_name(name, **options)
|
|
84
86
|
end
|
|
@@ -119,24 +121,19 @@ private
|
|
|
119
121
|
|
|
120
122
|
# Internal: Loads and merges the manifest files, resolving the asset paths.
|
|
121
123
|
def load_manifest
|
|
122
|
-
files = config.
|
|
124
|
+
files = [config.manifest_path, config.assets_manifest_path].select(&:exist?)
|
|
123
125
|
files.map { |path| JSON.parse(path.read) }.inject({}, &:merge).tap(&method(:resolve_references))
|
|
124
126
|
end
|
|
125
127
|
|
|
126
128
|
# Internal: Scopes an asset to the output folder in public, as a path.
|
|
127
129
|
def prefix_vite_asset(path)
|
|
128
|
-
File.join(
|
|
130
|
+
File.join("/#{ config.public_output_dir }", path)
|
|
129
131
|
end
|
|
130
132
|
|
|
131
133
|
# Internal: Prefixes an asset with the `asset_host` for tags that do not use
|
|
132
134
|
# the framework tag helpers.
|
|
133
135
|
def prefix_asset_with_host(path)
|
|
134
|
-
File.join(
|
|
135
|
-
end
|
|
136
|
-
|
|
137
|
-
# Internal: The origin of assets managed by Vite.
|
|
138
|
-
def vite_asset_origin
|
|
139
|
-
config.origin if dev_server_running? && config.skip_proxy
|
|
136
|
+
File.join(config.asset_host || '/', config.public_output_dir, path)
|
|
140
137
|
end
|
|
141
138
|
|
|
142
139
|
# Internal: Resolves the paths that reference a manifest entry.
|
|
@@ -17,27 +17,19 @@ class ViteRuby::MissingEntrypointError < ViteRuby::Error
|
|
|
17
17
|
#{ possible_causes(last_build) }
|
|
18
18
|
:troubleshooting:
|
|
19
19
|
#{ "\nContent in your manifests:\n#{ JSON.pretty_generate(manifest) }\n" if last_build.success }
|
|
20
|
-
#{ "Last build in #{ config.mode } mode:\n#{ last_build.to_json }\n"
|
|
20
|
+
#{ "Last build in #{ config.mode } mode:\n#{ last_build.to_json }\n" unless last_build.success.nil? }
|
|
21
21
|
MSG
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
def possible_causes(last_build)
|
|
25
|
-
if last_build.success == false
|
|
26
|
-
|
|
27
|
-
.sub(':mode:', config.mode)
|
|
28
|
-
.sub(':errors:', last_build.errors.to_s.gsub(/^(?!$)/, ' '))
|
|
29
|
-
elsif config.auto_build
|
|
30
|
-
DEFAULT_CAUSES
|
|
31
|
-
else
|
|
32
|
-
DEFAULT_CAUSES + NO_AUTO_BUILD_CAUSES
|
|
33
|
-
end
|
|
34
|
-
end
|
|
25
|
+
return FAILED_BUILD_CAUSES.sub(':mode:', config.mode) if last_build.success == false
|
|
26
|
+
return DEFAULT_CAUSES if config.auto_build
|
|
35
27
|
|
|
36
|
-
|
|
37
|
-
|
|
28
|
+
DEFAULT_CAUSES + NO_AUTO_BUILD_CAUSES
|
|
29
|
+
end
|
|
38
30
|
|
|
39
|
-
|
|
40
|
-
|
|
31
|
+
FAILED_BUILD_CAUSES = <<-MSG
|
|
32
|
+
- The last build failed. Try running `bin/vite build --clear --mode=:mode:` manually and check for errors.
|
|
41
33
|
MSG
|
|
42
34
|
|
|
43
35
|
DEFAULT_CAUSES = <<-MSG
|
data/lib/vite_ruby/runner.rb
CHANGED
|
@@ -8,7 +8,7 @@ class ViteRuby::Runner
|
|
|
8
8
|
|
|
9
9
|
# Public: Executes Vite with the specified arguments.
|
|
10
10
|
def run(argv, exec: false)
|
|
11
|
-
config.
|
|
11
|
+
Dir.chdir(config.root) {
|
|
12
12
|
cmd = command_for(argv)
|
|
13
13
|
return Kernel.exec(*cmd) if exec
|
|
14
14
|
|
|
@@ -23,15 +23,15 @@ private
|
|
|
23
23
|
|
|
24
24
|
extend Forwardable
|
|
25
25
|
|
|
26
|
-
def_delegators :@vite_ruby, :config, :logger
|
|
26
|
+
def_delegators :@vite_ruby, :config, :logger
|
|
27
27
|
|
|
28
28
|
# Internal: Returns an Array with the command to run.
|
|
29
29
|
def command_for(args)
|
|
30
|
-
[config.to_env
|
|
30
|
+
[config.to_env].tap do |cmd|
|
|
31
31
|
args = args.clone
|
|
32
32
|
cmd.push('node', '--inspect-brk') if args.delete('--inspect')
|
|
33
33
|
cmd.push('node', '--trace-deprecation') if args.delete('--trace_deprecation')
|
|
34
|
-
cmd.push(
|
|
34
|
+
cmd.push(vite_executable)
|
|
35
35
|
cmd.push(*args)
|
|
36
36
|
cmd.push('--mode', config.mode) unless args.include?('--mode') || args.include?('-m')
|
|
37
37
|
end
|
|
@@ -40,12 +40,6 @@ private
|
|
|
40
40
|
# Internal: Resolves to an executable for Vite.
|
|
41
41
|
def vite_executable
|
|
42
42
|
bin_path = config.vite_bin_path
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
if config.root.join('yarn.lock').exist?
|
|
46
|
-
%w[yarn vite]
|
|
47
|
-
else
|
|
48
|
-
["#{ `npm bin`.chomp }/vite"]
|
|
49
|
-
end
|
|
43
|
+
File.exist?(bin_path) ? bin_path : "#{ `npm bin`.chomp }/vite"
|
|
50
44
|
end
|
|
51
45
|
end
|
data/lib/vite_ruby/version.rb
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
class ViteRuby
|
|
4
|
-
VERSION = '
|
|
4
|
+
VERSION = '4.0.0.alpha1'
|
|
5
5
|
|
|
6
6
|
# Internal: Versions used by default when running `vite install`.
|
|
7
|
-
DEFAULT_VITE_VERSION = '^
|
|
8
|
-
DEFAULT_PLUGIN_VERSION = '^3.
|
|
7
|
+
DEFAULT_VITE_VERSION = '^2.7.7'
|
|
8
|
+
DEFAULT_PLUGIN_VERSION = '^3.0.5'
|
|
9
9
|
end
|
data/lib/vite_ruby.rb
CHANGED
|
@@ -11,10 +11,11 @@ loader.ignore("#{ __dir__ }/install")
|
|
|
11
11
|
loader.ignore("#{ __dir__ }/tasks")
|
|
12
12
|
loader.ignore("#{ __dir__ }/exe")
|
|
13
13
|
loader.inflector.inflect('cli' => 'CLI')
|
|
14
|
-
loader.inflector.inflect('ssr' => 'SSR')
|
|
15
14
|
loader.inflector.inflect('io' => 'IO')
|
|
16
15
|
loader.setup
|
|
17
16
|
|
|
17
|
+
require 'vite_ruby/version'
|
|
18
|
+
|
|
18
19
|
class ViteRuby
|
|
19
20
|
# Internal: Prefix used for environment variables that modify the configuration.
|
|
20
21
|
ENV_PREFIX = 'VITE_RUBY'
|
|
@@ -32,7 +33,7 @@ class ViteRuby
|
|
|
32
33
|
class << self
|
|
33
34
|
extend Forwardable
|
|
34
35
|
|
|
35
|
-
def_delegators :instance, :config, :
|
|
36
|
+
def_delegators :instance, :config, :commands, :env, :run, :run_proxy?
|
|
36
37
|
def_delegators :config, :mode
|
|
37
38
|
|
|
38
39
|
def instance
|
|
@@ -75,17 +76,11 @@ class ViteRuby
|
|
|
75
76
|
@logger ||= Logger.new($stdout)
|
|
76
77
|
end
|
|
77
78
|
|
|
78
|
-
# Public: Returns a digest of all the watched files, allowing to detect
|
|
79
|
-
# changes. Useful to perform version checks in single-page applications.
|
|
80
|
-
def digest
|
|
81
|
-
builder.send(:watched_files_digest)
|
|
82
|
-
end
|
|
83
|
-
|
|
84
79
|
# Public: Returns true if the Vite development server is currently running.
|
|
85
80
|
# NOTE: Checks only once every second since every lookup calls this method.
|
|
86
81
|
def dev_server_running?
|
|
87
82
|
return false unless run_proxy?
|
|
88
|
-
return true if @running_at && Time.now - @running_at < 1
|
|
83
|
+
return true if defined?(@running_at) && @running_at && Time.now - @running_at < 1
|
|
89
84
|
|
|
90
85
|
Socket.tcp(config.host, config.port, connect_timeout: config.dev_server_connect_timeout).close
|
|
91
86
|
@running_at = Time.now
|
|
@@ -128,22 +123,15 @@ class ViteRuby
|
|
|
128
123
|
# Public: Current instance configuration for Vite.
|
|
129
124
|
def config
|
|
130
125
|
unless defined?(@config)
|
|
131
|
-
|
|
126
|
+
@config = ViteRuby::Config.resolve_config(**@config_options)
|
|
132
127
|
@config.load_ruby_config
|
|
133
128
|
end
|
|
134
129
|
|
|
135
130
|
@config
|
|
136
131
|
end
|
|
137
132
|
|
|
138
|
-
# Public: Allows overriding the configuration for this instance.
|
|
139
|
-
def configure(**options)
|
|
140
|
-
@config = ViteRuby::Config.resolve_config(**@config_options, **options)
|
|
141
|
-
end
|
|
142
|
-
|
|
143
133
|
# Public: Enables looking up assets managed by Vite using name and type.
|
|
144
134
|
def manifest
|
|
145
135
|
@manifest ||= ViteRuby::Manifest.new(self)
|
|
146
136
|
end
|
|
147
137
|
end
|
|
148
|
-
|
|
149
|
-
require 'vite_ruby/version'
|
metadata
CHANGED
|
@@ -1,35 +1,29 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: vite_ruby
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 4.0.0.alpha1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Máximo Mussini
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2022-01-18 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: dry-cli
|
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
|
16
16
|
requirements:
|
|
17
|
-
- - "
|
|
18
|
-
- !ruby/object:Gem::Version
|
|
19
|
-
version: '0.7'
|
|
20
|
-
- - "<"
|
|
17
|
+
- - "~>"
|
|
21
18
|
- !ruby/object:Gem::Version
|
|
22
|
-
version:
|
|
19
|
+
version: 0.7.0
|
|
23
20
|
type: :runtime
|
|
24
21
|
prerelease: false
|
|
25
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
26
23
|
requirements:
|
|
27
|
-
- - "
|
|
28
|
-
- !ruby/object:Gem::Version
|
|
29
|
-
version: '0.7'
|
|
30
|
-
- - "<"
|
|
24
|
+
- - "~>"
|
|
31
25
|
- !ruby/object:Gem::Version
|
|
32
|
-
version:
|
|
26
|
+
version: 0.7.0
|
|
33
27
|
- !ruby/object:Gem::Dependency
|
|
34
28
|
name: rack-proxy
|
|
35
29
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -185,7 +179,6 @@ files:
|
|
|
185
179
|
- lib/vite_ruby/cli/dev.rb
|
|
186
180
|
- lib/vite_ruby/cli/file_utils.rb
|
|
187
181
|
- lib/vite_ruby/cli/install.rb
|
|
188
|
-
- lib/vite_ruby/cli/ssr.rb
|
|
189
182
|
- lib/vite_ruby/cli/upgrade.rb
|
|
190
183
|
- lib/vite_ruby/cli/upgrade_packages.rb
|
|
191
184
|
- lib/vite_ruby/cli/version.rb
|
|
@@ -208,8 +201,8 @@ homepage: https://github.com/ElMassimo/vite_ruby
|
|
|
208
201
|
licenses:
|
|
209
202
|
- MIT
|
|
210
203
|
metadata:
|
|
211
|
-
source_code_uri: https://github.com/ElMassimo/vite_ruby/tree/vite_ruby@
|
|
212
|
-
changelog_uri: https://github.com/ElMassimo/vite_ruby/blob/vite_ruby@
|
|
204
|
+
source_code_uri: https://github.com/ElMassimo/vite_ruby/tree/vite_ruby@4.0.0.alpha1/vite_ruby
|
|
205
|
+
changelog_uri: https://github.com/ElMassimo/vite_ruby/blob/vite_ruby@4.0.0.alpha1/vite_ruby/CHANGELOG.md
|
|
213
206
|
post_install_message: "Thanks for installing Vite Ruby!\n\nIf you upgraded the gem
|
|
214
207
|
manually, please run:\n\tbundle exec vite upgrade"
|
|
215
208
|
rdoc_options: []
|
|
@@ -219,14 +212,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
219
212
|
requirements:
|
|
220
213
|
- - ">="
|
|
221
214
|
- !ruby/object:Gem::Version
|
|
222
|
-
version: '2.
|
|
215
|
+
version: '2.4'
|
|
223
216
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
224
217
|
requirements:
|
|
225
|
-
- - "
|
|
218
|
+
- - ">"
|
|
226
219
|
- !ruby/object:Gem::Version
|
|
227
|
-
version:
|
|
220
|
+
version: 1.3.1
|
|
228
221
|
requirements: []
|
|
229
|
-
rubygems_version: 3.
|
|
222
|
+
rubygems_version: 3.2.32
|
|
230
223
|
signing_key:
|
|
231
224
|
specification_version: 4
|
|
232
225
|
summary: Use Vite in Ruby and bring joy to your JavaScript experience
|
data/lib/vite_ruby/cli/ssr.rb
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
class ViteRuby::CLI::SSR < ViteRuby::CLI::Vite
|
|
4
|
-
DEFAULT_ENV = CURRENT_ENV || 'production'
|
|
5
|
-
JS_EXTENSIONS = %w[js mjs cjs]
|
|
6
|
-
|
|
7
|
-
desc 'Run the resulting app from building in SSR mode.'
|
|
8
|
-
executable_options
|
|
9
|
-
|
|
10
|
-
def call(mode:, inspect: false, trace_deprecation: false)
|
|
11
|
-
ViteRuby.env['VITE_RUBY_MODE'] = mode
|
|
12
|
-
|
|
13
|
-
ssr_entrypoint = JS_EXTENSIONS
|
|
14
|
-
.map { |ext| ViteRuby.config.ssr_output_dir.join("ssr.#{ ext }") }
|
|
15
|
-
.find(&:exist?)
|
|
16
|
-
|
|
17
|
-
raise ArgumentError, "No ssr entrypoint found `#{ ViteRuby.config.ssr_output_dir.relative_path_from(ViteRuby.config.root) }/ssr.{#{ JS_EXTENSIONS.join(',') }}`. Have you run bin/vite build --ssr?" unless ssr_entrypoint
|
|
18
|
-
|
|
19
|
-
cmd = [
|
|
20
|
-
'node',
|
|
21
|
-
('--inspect-brk' if inspect),
|
|
22
|
-
('--trace-deprecation' if trace_deprecation),
|
|
23
|
-
ssr_entrypoint,
|
|
24
|
-
]
|
|
25
|
-
Kernel.exec(*cmd.compact.map(&:to_s))
|
|
26
|
-
end
|
|
27
|
-
end
|