You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- enable [Fast Refresh](https://www.npmjs.com/package/react-refresh) in development
6
6
- use the [automatic JSX runtime](https://legacy.reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html)
7
-
- dedupe the `react` and `react-dom` packages
8
7
- use custom Babel plugins/presets
8
+
- small installation size
9
9
10
10
```js
11
11
// vite.config.js
@@ -17,32 +17,38 @@ export default defineConfig({
17
17
})
18
18
```
19
19
20
-
## Filter which files use Fast Refresh
20
+
## Options
21
21
22
-
By default, Fast Refresh is used by files ending with `.js`, `.jsx`, `.ts`, and `.tsx`, except for files with a `node_modules` parent directory.
22
+
### include/exclude
23
23
24
-
In some situations, you may not want a file to act as a HMR boundary, instead preferring that the changes propagate higher in the stack before being handled. In these cases, you can provide an `include` and/or `exclude` option, which can be a regex, a [picomatch](https://github.com/micromatch/picomatch#globbing-features) pattern, or an array of either. Files matching `include` and not `exclude` will use Fast Refresh. The defaults are always applied.
24
+
Includes `.js`, `.jsx`, `.ts` & `.tsx` by default. This option can be used to add fast refresh to `.mdx` files:
25
25
26
26
```js
27
-
react({
28
-
// Exclude storybook stories
29
-
exclude:/\.stories\.(t|j)sx?$/,
30
-
// Only .tsx files
31
-
include:'**/*.tsx',
27
+
import { defineConfig } from'vite'
28
+
importreactfrom'@vitejs/plugin-react'
29
+
importmdxfrom'@mdx-js/rollup'
30
+
31
+
exportdefaultdefineConfig({
32
+
plugins: [
33
+
{ enforce:'pre', ...mdx() },
34
+
react({ include:/\.(mdx|js|jsx|ts|tsx)$/ }),
35
+
],
32
36
})
33
37
```
34
38
35
-
### Configure the JSX import source
39
+
> `node_modules` are never processed by this plugin (but esbuild will)
40
+
41
+
### jsxImportSource
36
42
37
-
Control where the JSX factory is imported from. For TS projects this is inferred from the tsconfig.
43
+
Control where the JSX factory is imported from. For TS projects this is inferred from the tsconfig. If you have some React code outside JSX/TSX files, this will be used to detect the presence of React code and apply Fast Refresh.
38
44
39
45
```js
40
46
react({ jsxImportSource:'@emotion/react' })
41
47
```
42
48
43
-
##Babel configuration
49
+
### babel
44
50
45
-
The `babel` option lets you add plugins, presets, and [other configuration](https://babeljs.io/docs/en/options) to the Babel transformation performed on each JSX/TSX file.
51
+
The `babel` option lets you add plugins, presets, and [other configuration](https://babeljs.io/docs/en/options) to the Babel transformation performed on each included file.
46
52
47
53
```js
48
54
react({
@@ -58,7 +64,9 @@ react({
58
64
})
59
65
```
60
66
61
-
### Proposed syntax
67
+
Note: When not using plugins, only esbuild is used for production builds, resulting in faster builds.
68
+
69
+
#### Proposed syntax
62
70
63
71
If you are using ES syntax that are still in proposal status (e.g. class properties), you can selectively enable them with the `babel.parserOpts.plugins` option:
0 commit comments