Skip to content

Commit 8da0f6c

Browse files
committed
chore: upgrade example rails app and demonstrate config/vite.rb
1 parent 0d8bcda commit 8da0f6c

File tree

8 files changed

+39
-21
lines changed

8 files changed

+39
-21
lines changed

examples/rails/Gemfile.lock

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ GEM
9999
ffi (1.15.3)
100100
globalid (0.5.2)
101101
activesupport (>= 5.0)
102-
i18n (1.8.10)
102+
i18n (1.8.11)
103103
concurrent-ruby (~> 1.0)
104104
jbuilder (2.11.2)
105105
activesupport (>= 5.0.0)
@@ -108,7 +108,7 @@ GEM
108108
listen (3.6.0)
109109
rb-fsevent (~> 0.10, >= 0.10.3)
110110
rb-inotify (~> 0.9, >= 0.9.10)
111-
loofah (2.12.0)
111+
loofah (2.13.0)
112112
crass (~> 1.0.2)
113113
nokogiri (>= 1.5.9)
114114
mail (2.7.1)
@@ -117,7 +117,7 @@ GEM
117117
method_source (1.0.0)
118118
mini_mime (1.1.0)
119119
mini_portile2 (2.6.1)
120-
minitest (5.14.4)
120+
minitest (5.15.0)
121121
msgpack (1.4.2)
122122
nio4r (2.5.8)
123123
nokogiri (1.12.5)
@@ -209,12 +209,12 @@ GEM
209209
turbolinks-source (5.2.0)
210210
tzinfo (2.0.4)
211211
concurrent-ruby (~> 1.0)
212-
vite_plugin_legacy (3.0.0)
213-
vite_ruby (~> 3.0)
214-
vite_rails (3.0.1)
212+
vite_plugin_legacy (3.0.2)
213+
vite_ruby (~> 3.0, >= 3.0.4)
214+
vite_rails (3.0.3)
215215
railties (>= 5.1, < 8)
216216
vite_ruby (~> 3.0)
217-
vite_ruby (3.0.2)
217+
vite_ruby (3.0.6)
218218
dry-cli (~> 0.7.0)
219219
rack-proxy (~> 0.6, >= 0.6.1)
220220
zeitwerk (~> 2.2)

examples/rails/app/frontend/entrypoints/application.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ import '~/styles/theme.css'
1313
import '~/entrypoints/example_import.js'
1414
import '~/outer_import.js'
1515

16+
// Example: Import from an aliased path.
17+
import '@administrator/timer'
18+
1619
// Import all channels.
1720
import.meta.globEager('../channels/**/*_channel.js')
1821

examples/rails/config/vite.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# frozen_string_literal: true
2+
3+
ViteRuby.env['ADMINISTRATOR_ASSETS_PATH'] =
4+
"#{ Gem.loaded_specs['administrator'].full_gem_path }/app/frontend"
Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
1-
function startTimer (timer, loadedAt = new Date().getTime()) {
2-
function updateTimer () {
3-
const millisEllapsed = new Date().getTime() - loadedAt
4-
timer.innerHTML = Math.floor(millisEllapsed / 1000)
5-
}
6-
7-
setInterval(updateTimer, 200)
8-
}
1+
import { startTimer } from '~/timer'
92

103
document.addEventListener('DOMContentLoaded', () => {
114
console.log('Vite ⚡️ Rails: Engine')
125
startTimer(document.getElementById('timer'))
136
})
14-
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export function startTimer (timer, loadedAt = new Date().getTime()) {
2+
function updateTimer () {
3+
const millisEllapsed = new Date().getTime() - loadedAt
4+
timer.innerHTML = Math.floor(millisEllapsed / 1000)
5+
}
6+
7+
setInterval(updateTimer, 200)
8+
}

examples/rails/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"vite-plugin-bugsnag": "^1.0.2",
2929
"vite-plugin-environment": "^1.0.0",
3030
"vite-plugin-full-reload": "^0.2",
31-
"vite-plugin-ruby": "^3.0.3",
31+
"vite-plugin-ruby": "^3.0.5",
3232
"vite-plugin-windicss": "^0.9"
3333
}
3434
}

examples/rails/vite.config.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,15 @@ export default defineConfig({
4141
},
4242
}),
4343
],
44+
// Example: Importing assets from arbitrary paths.
45+
resolve: {
46+
alias: {
47+
'@administrator/': `${process.env.ADMINISTRATOR_ASSETS_PATH}/`,
48+
},
49+
},
50+
server: {
51+
fs: {
52+
allow: [process.env.ADMINISTRATOR_ASSETS_PATH!],
53+
},
54+
},
4455
})

examples/rails/yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2244,10 +2244,10 @@ vite-plugin-full-reload@^0.2:
22442244
chalk "^4.1"
22452245
picomatch "^2.2.2"
22462246

2247-
vite-plugin-ruby@^3.0.3:
2248-
version "3.0.3"
2249-
resolved "https://registry.yarnpkg.com/vite-plugin-ruby/-/vite-plugin-ruby-3.0.3.tgz#e5fcbeaafe28c4b2a448af3a20fcbaa44c81d6b9"
2250-
integrity sha512-RZMYOmhGwWwyDh00YIwKV2tO377Pqeke1bk3XJS5hBRGUnS5qgHLp6bqZH9yeLCxmlJ5kgWUzNkDmDDhV2BmNQ==
2247+
vite-plugin-ruby@^3.0.5:
2248+
version "3.0.5"
2249+
resolved "https://registry.yarnpkg.com/vite-plugin-ruby/-/vite-plugin-ruby-3.0.5.tgz#b2601f832e043e023a07cea5a3bd87d24a8a1562"
2250+
integrity sha512-bFPnLxWxF1SyWtag24f48hYqLu0dydDs8tuIlvY60uHOY4yj6syCybZY21k3B9EgVtdGLve5twduj9bIoDuSug==
22512251
dependencies:
22522252
debug "^4.3.1"
22532253
fast-glob "^3.2.4"

0 commit comments

Comments
 (0)