Skip to content

Commit

Permalink
docs: update plugin-react-refresh README.md for middleware mode (#1856)…
Browse files Browse the repository at this point in the history
… [skip ci]
  • Loading branch information
pengx17 committed Feb 3, 2021
1 parent cd13ef0 commit 501bef2
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions packages/plugin-react-refresh/README.md
Expand Up @@ -35,3 +35,24 @@ export default {
- This option only enables the plugin to parse these syntax - it does not perform any transpilation since this plugin is dev-only.

- If you wish to transpile the syntax for production, you will need to configure the transform separately using [@rollup/plugin-babel](https://github.com/rollup/plugins/tree/master/packages/babel) as a build-only plugin.

## Middleware Mode Notes

When Vite is launched in **Middleware Mode**, you need to make sure your entry `index.html` file is transformed with `ViteDevServer.transformIndexHtml`. Otherwise, you may get an error prompting `Uncaught Error: vite-plugin-react can't detect preamble. Something is wrong.`

To mitigate this issue, you can explicitly transform your `index.html` like this when configuring your express server:

```ts
app.get('/', async (req, res, next) => {
try {
let html = fs.readFileSync(
path.resolve(root, 'index.html'),
'utf-8'
);
html = await viteServer.transformIndexHtml(req.url, html);
res.send(html);
} catch (e) {
return next(e);
}
});
```

0 comments on commit 501bef2

Please sign in to comment.