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,33 @@ 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: [mdx(), react({ include:/.mdx$/ })],
32
33
})
33
34
```
34
35
35
-
### Configure the JSX import source
36
+
### jsxImportSource
36
37
37
38
Control where the JSX factory is imported from. For TS projects this is inferred from the tsconfig.
38
39
39
40
```js
40
41
react({ jsxImportSource:'@emotion/react' })
41
42
```
42
43
43
-
##Babel configuration
44
+
### babel
44
45
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.
46
+
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
47
47
48
```js
48
49
react({
@@ -58,7 +59,9 @@ react({
58
59
})
59
60
```
60
61
61
-
### Proposed syntax
62
+
Note: When not using plugins, only esbuild is used for production builds, resulting in faster builds.
63
+
64
+
#### Proposed syntax
62
65
63
66
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