Vite HMR 無法偵測子資料夾內元件的更改
P粉854119263
P粉854119263 2023-11-04 09:37:46
0
1
408

在 Vue Vite 專案中,我有這樣的資料夾結構

問題是 vite 無法偵測 A.vue 或 B.vue 中的變更(ctrl s),即嵌套在元件資料夾中的 NestedFolder 下的元件。其他地方都工作正常。

我的 vite.config.js 看起來像這樣,

import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue()
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url)),
      '@public': fileURLToPath(new URL('./public', import.meta.url))
    }
  },
  server: {
    proxy: {
      '/api': {
        target: 'XXX',
        changeOrigin: true,
        secure: false,      
        ws: true,
      }
    }
  }
})

我已經按照 vite HMR API 文件嘗試了自訂 HMR 函數,讓它使用它來發送完全重新載入。

...
plugins: [
    vue(),
    {
      name: 'custom-hmr',
      enforce: 'post',
      // HMR
      handleHotUpdate({ file, server }) {
        if (file.endsWith('.vue')) {
          console.log('reloading json file...');
  
          server.ws.send({
            type: 'reload',          
            path: '*'
          });
        }
      },
    }
  ], ...

我查看了 vite 的 HMR API 文檔,但不知道如何在使用自訂 hmr 函數時向 vite 發送更新事件

任何有關如何解決此問題的幫助/建議將不勝感激。

P粉854119263
P粉854119263

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!