gloriasoft / veaury

Use React in Vue3 and Vue3 in React, And as perfect as possible!
MIT License
1.31k stars 83 forks source link

Work Perfectly but what about HMR? #12

Closed dmx974 closed 2 years ago

dmx974 commented 2 years ago

Hey, good job!

Just wanted to know how I can get HMR working on react components?

I have Vue3 + Vite + Veaury and a component folder with a react project inside. When I modify the react files, I cannot see the UI updated in real time, I need to refresh the browser. How to get this work?

devilwjp commented 2 years ago

@dmx974 Just add @vitejs/plugin-react-refresh to vite.config.js to solve your problem.

devilwjp commented 2 years ago
// vite.config.js
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import { babel } from '@rollup/plugin-babel'
import reactRefresh from '@vitejs/plugin-react-refresh'

export default defineConfig({
  plugins: [
    vue({}),
    vueJsx({
      // exclude react_app directory
      exclude: [/[/\\]react_app[\\/$]+/]
    }),
    // This configuration can create react jsx files in any react_app directory
    babel({
      exclude: [/node_modules/],
      presets: [
        '@vue/cli-plugin-babel/preset',
        'veaury/babel/ReactPreset'
      ],
      babelHelpers: 'runtime',
    }),
    reactRefresh({
      parserPlugins: ['classProperties', 'classPrivateProperties']
    })
  ]
})
dmx974 commented 2 years ago

It works like a charm, thank you for your reactivity!