Skip to content

Commit 54231d9

Browse files
authored
docs(plugin-react): add docs for exclude option (#1046)
1 parent 79bf57c commit 54231d9

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

packages/plugin-react/README.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ export default defineConfig({
1919

2020
## Options
2121

22-
### include/exclude
22+
### include
2323

24-
Includes `.js`, `.jsx`, `.ts` & `.tsx` and excludes `/node_modules/` by default. This option can be used to add fast refresh to `.mdx` files:
24+
Includes `.js`, `.jsx`, `.ts` & `.tsx` by default. This option can be used to add fast refresh to `.mdx` files:
2525

2626
```js
2727
import { defineConfig } from 'vite'
@@ -36,6 +36,22 @@ export default defineConfig({
3636
})
3737
```
3838

39+
### exclude
40+
41+
The default value is `/node_modules/`. You may use it to exclude JSX/TSX files that runs in a worker or are not React files.
42+
Except if explicitly desired, you should keep `node_modules` in the exclude list:
43+
44+
```js
45+
import { defineConfig } from 'vite'
46+
import react from '@vitejs/plugin-react'
47+
48+
export default defineConfig({
49+
plugins: [
50+
react({ exclude: [/\/pdf\//, /\.solid\.tsx$/, /\/node_modules\//] }),
51+
],
52+
})
53+
```
54+
3955
### jsxImportSource
4056

4157
Control where the JSX factory is imported from. By default, this is inferred from `jsxImportSource` from corresponding a tsconfig file for a transformed file.

packages/plugin-react/src/index.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,18 @@ async function loadBabel() {
3232
}
3333

3434
export interface Options {
35+
/**
36+
* Can be used to process extra files like `.mdx`
37+
* @example include: /\.(mdx|js|jsx|ts|tsx)$/
38+
* @default /\.[tj]sx?$/
39+
*/
3540
include?: string | RegExp | Array<string | RegExp>
41+
/**
42+
* Can be used to exclude JSX/TSX files that runs in a worker or are not React files.
43+
* Except if explicitly desired, you should keep node_modules in the exclude list
44+
* @example exclude: [/\/pdf\//, /\.solid\.tsx$/, /\/node_modules\//]
45+
* @default /\/node_modules\//
46+
*/
3647
exclude?: string | RegExp | Array<string | RegExp>
3748
/**
3849
* Control where the JSX factory is imported from.

0 commit comments

Comments
 (0)