Skip to content

Commit a5cbf07

Browse files
MoOxnecolas
authored andcommitted
Refactor Vite config and add necessary plugins
Updated Vite configuration to include plugins and CSS directives. Close react#439
1 parent 0f20263 commit a5cbf07

3 files changed

Lines changed: 34 additions & 7 deletions

File tree

packages/website/docs/learn/environment-setup/01-expo.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ module.exports = {
7474
require('react-strict-dom/postcss-plugin')({
7575
include: [
7676
// Include source files to watch for style changes
77+
// Be specific and avoid a non-specific glob like "**/*.{js,jsx}" which could cause major performance issues during build
7778
'src/**/*.{js,jsx,mjs,ts,tsx}',
7879
// List any installed node_modules that include UI built with React Strict DOM
7980
'node_modules/<package-name>/*.js'

packages/website/docs/learn/environment-setup/02-next.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,19 @@ export default config;
5454
import babelLoader from "./babelLoader.config.js";
5555

5656
const config = {
57-
plugins: [
57+
plugins: {
5858
"react-strict-dom/postcss-plugin": {
5959
include: [
6060
// Include source files to watch for style changes
61+
// Be specific and avoid a non-specific glob like "**/*.{js,jsx}" which could cause major performance issues during build
6162
'src/**/*.{js,jsx,mjs,ts,tsx}',
6263
// List any installed node_modules that include UI built with React Strict DOM
6364
'node_modules/<package-name>/*.js'
6465
],
6566
babelConfig: babelLoader,
6667
useLayers: true,
6768
}
68-
],
69+
},
6970
};
7071

7172
export default config;

packages/website/docs/learn/environment-setup/03-vite.md

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,30 +50,37 @@ export default {
5050
import babelLoader from "./babel.config.js";
5151

5252
export default {
53-
plugins: [
53+
plugins: {
5454
"react-strict-dom/postcss-plugin": {
5555
include: [
5656
// Include source files to watch for style changes
57+
// Be specific and avoid a non-specific glob like "**/*.{js,jsx}" which could cause major performance issues during build
5758
'src/**/*.{js,jsx,mjs,ts,tsx}',
5859
// List any installed node_modules that include UI built with React Strict DOM
5960
'node_modules/<package-name>/*.js'
6061
],
6162
babelConfig: babelLoader,
6263
useLayers: true,
6364
},
64-
],
65+
},
6566
};
6667
```
6768

6869
## Vite configuration
6970

71+
If you just created a brand new Vite app, you might need to install
72+
73+
```
74+
npm install vite-plugin-babel vite-tsconfig-paths
75+
```
76+
7077
Create or edit the `vite.config.ts` file as follows.
7178

7279
```js title="vite.config.ts"
7380
import { defineConfig } from "vite";
74-
import viteBabel from "vite-plugin-babel";
75-
import viteReact from "@vitejs/plugin-react";
7681
import tsConfigPaths from "vite-tsconfig-paths";
82+
import viteReact from "@vitejs/plugin-react";
83+
import viteBabel from "vite-plugin-babel";
7784

7885
export default defineConfig(() => ({
7986
plugins: [
@@ -92,7 +99,7 @@ export default defineConfig(() => ({
9299

93100
Your app needs to include a CSS file that contains a `@react-strict-dom` directive. This acts as a placeholder that is replaced by the generated CSS during builds.
94101

95-
```css title="strict.css"
102+
```css title="src/strict.css"
96103
/* This directive is used by the react-strict-dom postcss plugin. */
97104
/* It is automatically replaced with generated CSS during builds. */
98105
@react-strict-dom;
@@ -101,6 +108,8 @@ Your app needs to include a CSS file that contains a `@react-strict-dom` directi
101108
Next, import the CSS file in the `main.tsx` file.
102109

103110
```js title="src/main.tsx"
111+
// ...
112+
104113
// Required for CSS to work on Vite
105114
import "./strict.css";
106115

@@ -134,5 +143,21 @@ export default defineConfig(() => ({
134143
],
135144
},
136145
}));
146+
```
147+
148+
## Server-Side Rendering
149+
150+
If you plan to use SSR with Vite you will need to add the following `ssr` options.
151+
152+
```js title="vite.config.ts"
153+
import { defineConfig } from "vite";
137154

155+
//...
156+
157+
export default defineConfig(() => ({
158+
// ...
159+
ssr: {
160+
noExternal: ["react-strict-dom"],
161+
},
162+
}));
138163
```

0 commit comments

Comments
 (0)