vite_ruby 3.3.4 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 579d77a9b6f100195112e6ee0fc66d445f35aca1d079c24c9548ea6b708af472
4
- data.tar.gz: 13b18e4418675330c2d974b41a56b4dac97a4b4f3f10cffb1216d9370b386a52
3
+ metadata.gz: 3e369fc30038cbf7475208298ccc3eebbcec6ad98100b785d6303b766afc3aad
4
+ data.tar.gz: '0811dc3a900d49b9b0b3c406b32b96e852d5a367dce1c96924b6b0a936fddc39'
5
5
  SHA512:
6
- metadata.gz: cf5e33d054b13211aeccbcccd96c2c03e8bae08c56c5ad52ffbac39a045b423a393b5e80fec15a7ad56929d4f8db09230b7d71260bd7fd0dd05478b0db661b54
7
- data.tar.gz: 334056f48cbf9799e3522aaf575e657b6f7c6b7d825adf59ed602a45d1654d5d97a362b80aec578a836b4bd6ad084b740c4822ba1d99dab1c6ef2ce8a1343f2d
6
+ metadata.gz: ef190e8c53cf93255f56a69fa7db7fe684f1fc4924b21aca81d9d2160ec117accf643771a5692bf58225884958fa06fc3b1e713241eaa6f2f223b8fca35e216a
7
+ data.tar.gz: 22b63dc5256c147ddf084f0324f2e6a236b86b654e6cd63e99da2608c6869290aa80885b8d9c61f8c7056df449464cb24831717de5e1a0857b5cf28af303700c
data/CHANGELOG.md CHANGED
@@ -1,297 +1,9 @@
1
- ## [3.3.4](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@3.3.3...vite_ruby@3.3.4) (2023-06-27)
2
-
3
-
4
- ### Bug Fixes
5
-
6
- * check only once per second when dev server is not running ([#377](https://github.com/ElMassimo/vite_ruby/issues/377)) ([fb33f0a](https://github.com/ElMassimo/vite_ruby/commit/fb33f0a28077f9912deed257b7be3a7e050c2d94))
7
-
8
-
9
-
10
- ## [3.3.3](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@3.3.2...vite_ruby@3.3.3) (2023-06-19)
11
-
12
-
13
- ### Features
14
-
15
- * allow skipping dev dependencies on install ([#374](https://github.com/ElMassimo/vite_ruby/issues/374)) ([a309f4f](https://github.com/ElMassimo/vite_ruby/commit/a309f4f9fc62fb7b9d0728b66b30ad90e68ba7bf))
16
- * Use javascript_tag helper for vite_react_refresh_tag ([#372](https://github.com/ElMassimo/vite_ruby/issues/372)) ([238c6bd](https://github.com/ElMassimo/vite_ruby/commit/238c6bd211c0fafaa6170f0bdd631a0f6e41d992)), closes [#249](https://github.com/ElMassimo/vite_ruby/issues/249)
17
-
18
-
19
-
20
- ## [3.3.2](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@3.3.1...vite_ruby@3.3.2) (2023-05-09)
21
-
22
-
23
- ### Bug Fixes
24
-
25
- * ensure assets:precompile task is displayed when using `rake -T` ([66af6eb](https://github.com/ElMassimo/vite_ruby/commit/66af6eb0268e7a989562feb38da74072817f0d49))
26
-
27
-
28
-
29
- ## [3.3.1](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@3.3.0...vite_ruby@3.3.1) (2023-04-28)
30
-
31
-
32
- ### Features
33
-
34
- * upgrade default vite version to 4.3 ([b186456](https://github.com/ElMassimo/vite_ruby/commit/b18645605dd40b312da1137a6440abc8fe4c5ae7))
35
-
36
-
37
-
38
- # [3.3.0](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@3.2.15...vite_ruby@3.3.0) (2023-03-16)
1
+ # [](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@3.0.8...vite_ruby@) (2022-01-18)
39
2
 
40
3
 
41
4
  ### Features
42
5
 
43
- * add support for the --profile flag when running vite build ([4a949fd](https://github.com/ElMassimo/vite_ruby/commit/4a949fde1672b899c7c0382e99a669195c7ea639)), closes [#332](https://github.com/ElMassimo/vite_ruby/issues/332)
44
- * change defaults to vite@4.2.0 and vite-plugin-ruby@3.2.0 ([e9f5702](https://github.com/ElMassimo/vite_ruby/commit/e9f570294c34682a6dd18fdc2ef13675f33375e6))
45
-
46
-
47
-
48
- ## [3.2.15](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@3.2.14...vite_ruby@3.2.15) (2023-03-01)
49
-
50
-
51
- ### Features
52
-
53
- * 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)
54
-
55
-
56
-
57
- ## [3.2.14](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@3.2.13...vite_ruby@3.2.14) (2022-12-22)
58
-
59
-
60
-
61
- ## [3.2.13](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@3.2.12...vite_ruby@3.2.13) (2022-12-09)
62
-
63
-
64
- ### Features
65
-
66
- * install vite 4 by default ([c1a2e16](https://github.com/ElMassimo/vite_ruby/commit/c1a2e16a5b47225c53ad73b4f6371f2108881850))
67
-
68
-
69
-
70
- ## [3.2.12](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@3.2.11...vite_ruby@3.2.12) (2022-12-02)
71
-
72
-
73
- ### Features
74
-
75
- * add experimental `skipProxy` setting ([#315](https://github.com/ElMassimo/vite_ruby/issues/315)) ([e9285f6](https://github.com/ElMassimo/vite_ruby/commit/e9285f62c76cc0cbbc5dc99d977e8aef30d08b6f))
76
- * add ViteRuby.instance.configure API to be used in config/vite.rb ([b5b8681](https://github.com/ElMassimo/vite_ruby/commit/b5b8681f85f5388a56d72c9b05dbfc95d5ba607b))
77
-
78
-
79
- ### Performance Improvements
80
-
81
- * avoid calculating digest on each lookup ([#314](https://github.com/ElMassimo/vite_ruby/issues/314)) ([62df93a](https://github.com/ElMassimo/vite_ruby/commit/62df93a15c09c652a8b7496e26cf85d5d69acce7))
82
-
83
-
84
-
85
- ## [3.2.11](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@3.2.10...vite_ruby@3.2.11) (2022-11-13)
86
-
87
-
88
- ### Bug Fixes
89
-
90
- * 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))
91
-
92
-
93
-
94
- ## [3.2.10](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@3.2.9...vite_ruby@3.2.10) (2022-11-03)
95
-
96
-
97
-
98
- ## [3.2.9](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@3.2.8...vite_ruby@3.2.9) (2022-11-02)
99
-
100
-
101
- ### Features
102
-
103
- * allow different ViteRuby instances to set different env vars ([25628a7](https://github.com/ElMassimo/vite_ruby/commit/25628a752cbd4828547c1f454cc4cb2217a591e0))
104
- * 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)
105
-
106
-
107
-
108
- ## [3.2.8](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@3.2.7...vite_ruby@3.2.8) (2022-10-28)
109
-
110
-
111
- ### Features
112
-
113
- * default to vite@3.2.0 ([2ef83a5](https://github.com/ElMassimo/vite_ruby/commit/2ef83a52148f46534c4106015f3f54ec9ee807cb))
114
-
115
-
116
-
117
- ## [3.2.7](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@3.2.6...vite_ruby@3.2.7) (2022-10-19)
118
-
119
-
120
- ### Bug Fixes
121
-
122
- * yarn berry pnp mode support ([#278](https://github.com/ElMassimo/vite_ruby/issues/278)) ([1890447](https://github.com/ElMassimo/vite_ruby/commit/189044746e536847cb33fb471cc7c42251a61072))
123
-
124
-
125
- ### Features
126
-
127
- * 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))
128
-
129
-
130
-
131
- ## [3.2.6](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@3.2.5...vite_ruby@3.2.6) (2022-10-07)
132
-
133
-
134
- ### Features
135
-
136
- * 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))
137
-
138
-
139
-
140
- ## [3.2.5](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@3.2.4...vite_ruby@3.2.5) (2022-10-07)
141
-
142
-
143
- ### Features
144
-
145
- * display last build errors in MissingEntrypointError ([#274](https://github.com/ElMassimo/vite_ruby/issues/274)) ([107c980](https://github.com/ElMassimo/vite_ruby/commit/107c980449546ef73c527b88f1db11a7201e4438))
146
-
147
-
148
-
149
- ## [3.2.4](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@3.2.3...vite_ruby@3.2.4) (2022-10-04)
150
-
151
-
152
- ### Bug Fixes
153
-
154
- * **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)
155
-
156
-
157
-
158
- ## [3.2.3](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@3.2.2...vite_ruby@3.2.3) (2022-08-28)
159
-
160
-
161
- ### Bug Fixes
162
-
163
- * 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))
164
-
165
-
166
-
167
- ## [3.2.2](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@3.2.1...vite_ruby@3.2.2) (2022-08-12)
168
-
169
-
170
- ### Features
171
-
172
- * allow framework-specific libraries to extend the CLI ([a0ed66f](https://github.com/ElMassimo/vite_ruby/commit/a0ed66fe64fb2549cecc358ccd60c82be44255aa))
173
-
174
-
175
-
176
- ## [3.2.1](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@3.2.0...vite_ruby@3.2.1) (2022-08-11)
177
-
178
-
179
- ### Bug Fixes
180
-
181
- * 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))
182
-
183
-
184
-
185
- # [3.2.0](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@3.1.7...vite_ruby@3.2.0) (2022-07-13)
186
-
187
-
188
- ### Features
189
-
190
- * use Vite 3 as the default ([#225](https://github.com/ElMassimo/vite_ruby/issues/225)) ([8fab191](https://github.com/ElMassimo/vite_ruby/commit/8fab1912dc8c7c600854b490c09a603644714266))
191
-
192
-
193
-
194
- ## [3.1.7](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@3.1.6...vite_ruby@3.1.7) (2022-07-13)
195
-
196
-
197
- ### Bug Fixes
198
-
199
- * 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)
200
- # [](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@3.1.6...vite_ruby@) (2022-07-01)
201
-
202
-
203
- ## [3.1.6](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@3.1.5...vite_ruby@3.1.6) (2022-06-02)
204
-
205
- ### Bug Fixes
206
-
207
- * Catch npm command not found, for folks who install deps with yarn ([7a0407b3211e682bc1da40d29225af58d3396cbd](https://github.com/ElMassimo/vite_ruby/commit/7a0407b3211e682bc1da40d29225af58d3396cbd))
208
-
209
-
210
- ## [3.1.5](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@3.1.4...vite_ruby@3.1.5) (2022-05-30)
211
-
212
-
213
- ### Bug Fixes
214
-
215
- * 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)
216
-
217
-
218
-
219
- ## [3.1.4](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@3.1.3...vite_ruby@3.1.4) (2022-05-13)
220
-
221
-
222
- ### Features
223
-
224
- * expose `ViteRuby.digest` to simplify asset versioning. ([ff92ce6](https://github.com/ElMassimo/vite_ruby/commit/ff92ce6011d857efa83987d3c20d48767111e700))
225
-
226
-
227
-
228
- ## [3.1.3](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@3.1.2...vite_ruby@3.1.3) (2022-05-13)
229
-
230
-
231
- ### Bug Fixes
232
-
233
- * change default for ssrOutputDir so it's ignored by default ([2f93b76](https://github.com/ElMassimo/vite_ruby/commit/2f93b762b29462cc619527ed47e6fa3cf8d3c8c9))
234
-
235
-
236
-
237
- ## [3.1.2](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@3.1.1...vite_ruby@3.1.2) (2022-05-12)
238
-
239
-
240
- ### Features
241
-
242
- * add support for SSR builds (experimental) ([#212](https://github.com/ElMassimo/vite_ruby/issues/212)) ([4d6cd2b](https://github.com/ElMassimo/vite_ruby/commit/4d6cd2b84f670b1703e3bde7033e822be97bf505))
243
- * ignore any vite dirs in .gitignore installation (for ssr builds) ([fd68420](https://github.com/ElMassimo/vite_ruby/commit/fd68420dfaeb79b97f8edade5bf17bfe81fd2486))
244
-
245
-
246
-
247
- ## [3.1.1](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@3.1.0...vite_ruby@3.1.1) (2022-04-14)
248
-
249
-
250
- ### Bug Fixes
251
-
252
- * 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))
253
-
254
-
255
-
256
- # [3.1.0](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@3.0.11...vite_ruby@3.1.0) (2022-04-01)
257
-
258
-
259
- ### Features
260
-
261
- * 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))
262
-
263
-
264
-
265
- ## [3.0.11](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@3.0.10...vite_ruby@3.0.11) (2022-04-01)
266
-
267
-
268
- ### Features
269
-
270
- * bump the default vite version ([2cb8952](https://github.com/ElMassimo/vite_ruby/commit/2cb895246b3154322273989057bf9bdc67634bc6))
271
-
272
-
273
-
274
- ## [3.0.10](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@3.0.9...vite_ruby@3.0.10) (2022-03-17)
275
-
276
-
277
- ### Bug Fixes
278
-
279
- * avoid proxying requests starting with @ ([93d071b](https://github.com/ElMassimo/vite_ruby/commit/93d071b2b807c2e09e24d5d7ea4228974b370960))
280
- * MissingExecutableError when deploying with Capistrano (close [#192](https://github.com/ElMassimo/vite_ruby/issues/192)) ([22e1691](https://github.com/ElMassimo/vite_ruby/commit/22e1691a0685b1fdeec3904657be5e69a57e6456))
281
-
282
-
283
- ### Features
284
-
285
- * bump up default vite version to 2.8.6 ([fd53030](https://github.com/ElMassimo/vite_ruby/commit/fd5303017760dc176b3fb15908f08a16a175c22f))
286
-
287
-
288
-
289
- ## [3.0.9](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@3.0.8...vite_ruby@3.0.9) (2022-02-09)
290
-
291
-
292
- ### Bug Fixes
293
-
294
- * 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))
295
7
 
296
8
 
297
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
@@ -7,6 +7,4 @@ require 'bundler/setup'
7
7
  require 'vite_ruby'
8
8
 
9
9
  cli = ViteRuby::CLI
10
- cli.require_framework_libraries
11
-
12
10
  Dry::CLI.new(cli).call
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 'Bundle frontend entrypoints using ViteRuby'
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 'Bundle a Node.js app from the SSR entrypoint using ViteRuby'
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 for ViteRuby'
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 'Verify if ViteRuby is properly installed in the app'
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 'Ensure build dependencies like Vite are installed before bundling'
32
+ desc 'Ensures build dependencies like Vite are installed when compiling assets'
44
33
  task :install_dependencies do
45
- install_env_args = ENV['VITE_RUBY_SKIP_INSTALL_DEV_DEPENDENCIES'] == 'true' ? {} : { 'NODE_ENV' => 'development' }
46
- cmd = ViteRuby.commands.legacy_npm_version? ? 'npx ci --yes' : 'npx --yes ci'
47
- result = system(install_env_args, cmd)
48
- # Fallback to `yarn` if `npx` is not available.
49
- system(install_env_args, '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,41 +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:install_dependencies"].invoke
63
- Rake::Task["#{ prefix }vite:build_all"].invoke
64
- end
65
- else
66
- desc 'Bundle Vite assets'
67
- Rake::Task.define_task('assets:precompile' => ['vite:install_dependencies', 'vite:build_all'])
68
- end
69
-
70
- unless Rake::Task.task_defined?('assets:clean')
71
- desc 'Remove old compiled assets'
72
- Rake::Task.define_task('assets:clean', [:keep, :age])
73
- end
74
- Rake::Task['assets:clean'].enhance do |_, args|
75
- Rake::Task['vite:clean'].invoke(*args.to_h.values)
76
- end
77
-
78
- if Rake::Task.task_defined?('assets:clobber')
79
- Rake::Task['assets:clobber'].enhance do
80
- Rake::Task['vite:clobber'].invoke
47
+ Rake::Task["#{ prefix }vite:build"].invoke
81
48
  end
82
49
  else
83
- desc 'Remove compiled assets'
84
- Rake::Task.define_task('assets:clobber' => 'vite:clobber')
50
+ Rake::Task.define_task('assets:precompile' => ['vite:install_dependencies', 'vite:build'])
85
51
  end
86
52
  end
87
53
 
88
54
  # Any prerequisite task that installs packages should also install build dependencies.
89
55
  if ARGV.include?('assets:precompile')
90
- if ViteRuby.commands.legacy_npm_version?
91
- ENV['NPM_CONFIG_PRODUCTION'] = 'false'
92
- else
93
- ENV['NPM_CONFIG_INCLUDE'] = 'dev'
94
- end
95
-
96
- if ViteRuby.commands.legacy_yarn_version?
97
- ENV['YARN_PRODUCTION'] = 'false'
98
- end
56
+ ENV['NPM_CONFIG_PRODUCTION'] = 'false'
57
+ ENV['YARN_PRODUCTION'] = 'false'
99
58
  end
@@ -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, :last_build_path, :errors, keyword_init: true) do
8
- class << self
9
- # Internal: Combines information from a previous build with the current digest.
10
- def from_previous(last_build_path, current_digest)
11
- new(
12
- **parse_metadata(last_build_path),
13
- current_digest: current_digest,
14
- last_build_path: last_build_path,
15
- )
16
- end
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(**attrs)
39
+ def with_result(success)
57
40
  self.class.new(
58
- **attrs,
59
- timestamp: Time.now.strftime('%F %T'),
60
- vite_ruby: ViteRuby::VERSION,
61
- digest: current_digest,
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
@@ -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(ssr: args.include?('--ssr'))
15
-
16
- if args.delete('--force') || last_build.stale? || config.manifest_paths.empty?
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(ssr: false)
32
- ViteRuby::Build.from_previous(last_build_path(ssr: ssr), watched_files_digest)
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(build, **attrs)
46
+ def record_build_metadata(success, build)
43
47
  config.build_cache_dir.mkpath
44
- build.with_result(**attrs).write_to_cache
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(ssr:)
49
- config.build_cache_dir.join("last#{ '-ssr' if ssr }-build-#{ config.mode }.json")
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
- return @last_digest if @last_digest_at && Time.now - @last_digest_at < 1
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
- @last_digest_at = Time.now
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
@@ -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
@@ -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.executable_options
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')
@@ -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.ssr_output_dir, config.build_cache_dir, config.vite_cache_dir]
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.within_root do
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.manifest_paths - current_version_files
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/#skipcompatibilitycheck
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
 
@@ -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(env_vars = ViteRuby.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(env_vars)
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['ssr_output_dir'] = config['root'].join(config['ssr_output_dir'])
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
- }.select { |_, value| value }
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(/\.(sass|scss|styl|stylus|less|pcss|postcss)\.css$/, '.\1') # Rails' stylesheet_link_tag always adds the extension.
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?(vite_url_prefix) # Vite asset
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
- # NOTE: Vite is configured to use 'public_output_dir' as the base, which can
69
- # be customized by the user in development to not match any of the routes.
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
@@ -15,7 +15,7 @@ module ViteRuby::IO
15
15
  stdin.close
16
16
  out = Thread.new { read_lines(stdout, &with_output) }
17
17
  err = Thread.new { stderr.read }
18
- [out.value, err.value.to_s, wait_threads.value]
18
+ [out.value, err.value, wait_threads.value]
19
19
  }
20
20
  end
21
21
 
@@ -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 `"autoBuild": true` in `config/vite.json` file will trigger a build
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 scripts, imported modules, and stylesheets for the specified
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
- scripts: script_paths,
34
- imports: imports.map { |entry| entry.fetch('file') }.uniq,
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
@@ -51,27 +50,21 @@ class ViteRuby::Manifest
51
50
  if dev_server_running?
52
51
  <<~REACT_REFRESH
53
52
  <script type="module">
54
- #{ react_preamble_code }
53
+ import RefreshRuntime from '#{ prefix_asset_with_host('@react-refresh') }'
54
+ RefreshRuntime.injectIntoGlobalHook(window)
55
+ window.$RefreshReg$ = () => {}
56
+ window.$RefreshSig$ = () => (type) => type
57
+ window.__vite_plugin_react_preamble_installed__ = true
55
58
  </script>
56
59
  REACT_REFRESH
57
60
  end
58
61
  end
59
62
 
60
- # Public: Source script for the React Refresh plugin.
61
- def react_preamble_code
62
- if dev_server_running?
63
- <<~REACT_PREAMBLE_CODE
64
- import RefreshRuntime from '#{ prefix_asset_with_host('@react-refresh') }'
65
- RefreshRuntime.injectIntoGlobalHook(window)
66
- window.$RefreshReg$ = () => {}
67
- window.$RefreshSig$ = () => (type) => type
68
- window.__vite_plugin_react_preamble_installed__ = true
69
- REACT_PREAMBLE_CODE
70
- end
71
- end
72
-
73
63
  protected
74
64
 
65
+ # Internal: Returns a [src, attrs] entry.
66
+ TO_ENTRY = ->(entry) { [entry.fetch('file'), entry.slice('integrity').symbolize_keys] }
67
+
75
68
  # Internal: Strict version of lookup.
76
69
  #
77
70
  # Returns a relative path for the asset, or raises an error if not found.
@@ -87,7 +80,7 @@ protected
87
80
  # manifest.lookup('calendar.js')
88
81
  # => { "file" => "/vite/assets/calendar-1016838bab065ae1e122.js", "imports" => [] }
89
82
  def lookup(name, **options)
90
- @build_mutex.synchronize { builder.build || (return nil) } if should_build?
83
+ @build_mutex.synchronize { builder.build } if should_build?
91
84
 
92
85
  find_manifest_entry resolve_entry_name(name, **options)
93
86
  end
@@ -128,24 +121,19 @@ private
128
121
 
129
122
  # Internal: Loads and merges the manifest files, resolving the asset paths.
130
123
  def load_manifest
131
- files = config.manifest_paths
124
+ files = [config.manifest_path, config.assets_manifest_path].select(&:exist?)
132
125
  files.map { |path| JSON.parse(path.read) }.inject({}, &:merge).tap(&method(:resolve_references))
133
126
  end
134
127
 
135
128
  # Internal: Scopes an asset to the output folder in public, as a path.
136
129
  def prefix_vite_asset(path)
137
- File.join(vite_asset_origin || '/', config.public_output_dir, path)
130
+ File.join("/#{ config.public_output_dir }", path)
138
131
  end
139
132
 
140
133
  # Internal: Prefixes an asset with the `asset_host` for tags that do not use
141
134
  # the framework tag helpers.
142
135
  def prefix_asset_with_host(path)
143
- File.join(vite_asset_origin || config.asset_host || '/', config.public_output_dir, path)
144
- end
145
-
146
- # Internal: The origin of assets managed by Vite.
147
- def vite_asset_origin
148
- config.origin if dev_server_running? && config.skip_proxy
136
+ File.join(config.asset_host || '/', config.public_output_dir, path)
149
137
  end
150
138
 
151
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" if last_build.success }
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
- FAILED_BUILD_CAUSES
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
- FAILED_BUILD_CAUSES = <<~MSG
37
- - The last build failed. Try running `bin/vite build --clear --mode=:mode:` manually and check for errors.
28
+ DEFAULT_CAUSES + NO_AUTO_BUILD_CAUSES
29
+ end
38
30
 
39
- Errors:
40
- :errors:
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
@@ -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.within_root {
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, :env
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(env)].tap do |cmd|
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(*vite_executable)
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
- return [bin_path] if File.exist?(bin_path)
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
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class ViteRuby
4
- VERSION = '3.3.4'
4
+ VERSION = '4.0.0.alpha1'
5
5
 
6
6
  # Internal: Versions used by default when running `vite install`.
7
- DEFAULT_VITE_VERSION = '^4.3.0'
8
- DEFAULT_PLUGIN_VERSION = '^3.2.0'
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, :configure, :commands, :digest, :env, :run, :run_proxy?
36
+ def_delegators :instance, :config, :commands, :env, :run, :run_proxy?
36
37
  def_delegators :config, :mode
37
38
 
38
39
  def instance
@@ -75,26 +76,17 @@ 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 @running if defined?(@running) && Time.now - @running_checked_at < 1
89
-
90
- begin
91
- Socket.tcp(config.host, config.port, connect_timeout: config.dev_server_connect_timeout).close
92
- @running = true
93
- rescue StandardError
94
- @running = false
95
- ensure
96
- @running_checked_at = Time.now
97
- end
83
+ return true if defined?(@running_at) && @running_at && Time.now - @running_at < 1
84
+
85
+ Socket.tcp(config.host, config.port, connect_timeout: config.dev_server_connect_timeout).close
86
+ @running_at = Time.now
87
+ true
88
+ rescue StandardError
89
+ @running_at = false
98
90
  end
99
91
 
100
92
  # Public: Additional environment variables to pass to Vite.
@@ -131,22 +123,15 @@ class ViteRuby
131
123
  # Public: Current instance configuration for Vite.
132
124
  def config
133
125
  unless defined?(@config)
134
- configure
126
+ @config = ViteRuby::Config.resolve_config(**@config_options)
135
127
  @config.load_ruby_config
136
128
  end
137
129
 
138
130
  @config
139
131
  end
140
132
 
141
- # Public: Allows overriding the configuration for this instance.
142
- def configure(**options)
143
- @config = ViteRuby::Config.resolve_config(**@config_options, **options)
144
- end
145
-
146
133
  # Public: Enables looking up assets managed by Vite using name and type.
147
134
  def manifest
148
135
  @manifest ||= ViteRuby::Manifest.new(self)
149
136
  end
150
137
  end
151
-
152
- 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: 3.3.4
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: 2023-06-27 00:00:00.000000000 Z
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: '2'
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: '2'
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@3.3.4/vite_ruby
212
- changelog_uri: https://github.com/ElMassimo/vite_ruby/blob/vite_ruby@3.3.4/vite_ruby/CHANGELOG.md
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.5'
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: '0'
220
+ version: 1.3.1
228
221
  requirements: []
229
- rubygems_version: 3.3.7
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
@@ -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