-
|
Our app is built with a micro-frontend architecture. Our projects on vite do not have HMR yet. I am trying to add it with the vite-plugin-react. Most of our micro frontends are vite bundled HTML Custom Elements running with React under the hood. When developing locally, we serve our real site, but replace the assets related to our "micro component" with the vite dev server. i.e. server: {
proxy: {
['^\\/(?!src|sandbox|dev|node_modules|package|@).*']: { // everything not handled by vite's dev server
target: <my site URL>,
changeOrigin: true,
followRedirects: true,
secure: false,
},
},
},When adding the With earlier versions of vite plugin react (3-), I built a plugin this way: const preambleScript = `import RefreshRuntime from "/@react-refresh";
RefreshRuntime.injectIntoGlobalHook(window);
window.__vite_plugin_react_preamble_installed__ = true;
if (!window.$RefreshReg$) window.$RefreshReg$ = () => {};
if (!window.$RefreshSig$) window.$RefreshSig$ = () => type => type;
`;
// ... plugin config:
configResolved(config) {
skipFastRefresh = config.isProduction || config.command === 'build' || config.server.hmr === false;
},
transform(inputCode, _id, _options) {
if (skipFastRefresh) return;
const code = inputCode.replace('import RefreshRuntime from "/@react-refresh";', preambleScript);
const ms = new MagicString(code);
return {
code: ms.toString(),
map: maps ? ms.generateMap(maps) : undefined,
};
},This no longer works properly with 4+. Could somebody provide any tips on how I could get this to work? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
Got it. Since version 5, you can add But I am still getting this issue: #958 |
Beta Was this translation helpful? Give feedback.
Got it. Since version 5, you can add
import '@vitejs/plugin-react/preamble';to your lib entry point.But I am still getting this issue: #958