我创建了一个rails应用程序,并安装了vite_rails gem。我的打字稿位于 app/frontend 文件夹中。
但是,保存 TS 文件时热重载不起作用。
我还尝试安装 vite-plugin-full-reload NPM 包。这是我的 vite 配置:
// vite.config.ts
import { fileURLToPath, URL } from 'node:url'
import { defineConfig } from 'vite'
import FullReload from 'vite-plugin-full-reload'
import RubyPlugin from 'vite-plugin-ruby'
import vue from '@vitejs/plugin-vue'
export default defineConfig({
plugins: [
RubyPlugin(),
vue(),
FullReload(['config/routes.rb', 'app/views/**/*', 'app/frontend/**/*']),
],
resolve: {
alias: {
'@': fileURLToPath(new URL('./app/frontend/internal', import.meta.url)),
},
},
})
还是没有重新加载,为什么?
这是来自使用 vite-dev 的工作 docker-compose.yml 的示例:
app:
build:
context: .
depends_on:
- database
- redis
- vite
entrypoint: ./entrypoints/docker-entrypoint.sh
command: ["rails", "server", "-b", "0.0.0.0"]
ports:
- 3000:3000
env_file: .env
environment:
RAILS_ENV: development
DOCKER: true
VITE_RUBY_HOST: vite
VITE_RUBY_PORT: 5173
stdin_open: true
tty: true
vite:
build:
context: .
entrypoint: ./entrypoints/docker-vite.sh
environment:
DEBUG: '*vite*'
RAILS_ENV: development
VITE_RUBY_HOST: 0.0.0.0
VITE_RUBY_PORT: 5173
ports:
- 5173:5173
入口点/docker-vite.sh就是这样:
#!/bin/sh
yarn install
bin/vite dev