-
Notifications
You must be signed in to change notification settings - Fork 195
Refactor Vite config and add necessary plugins #439
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
c680e4a
Refactor Vite config and add necessary plugins
MoOx 16dd913
Fix Next docs configuration structure for PostCSS plugins
MoOx aa9b825
Update Expo postcss config comment for performance optimization
MoOx 0c4630f
Apply suggestions from code review
MoOx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -50,30 +50,37 @@ export default { | |||||||||||||
| import babelLoader from "./babel.config.js"; | ||||||||||||||
|
|
||||||||||||||
| export default { | ||||||||||||||
| plugins: [ | ||||||||||||||
| plugins: { | ||||||||||||||
| "react-strict-dom/postcss-plugin": { | ||||||||||||||
| include: [ | ||||||||||||||
| // Include source files to watch for style changes | ||||||||||||||
| // Be specific and avoid a non-specific glob like "**/*.{js,jsx}" which could cause major performance issues during build | ||||||||||||||
| 'src/**/*.{js,jsx,mjs,ts,tsx}', | ||||||||||||||
| // List any installed node_modules that include UI built with React Strict DOM | ||||||||||||||
| 'node_modules/<package-name>/*.js' | ||||||||||||||
| ], | ||||||||||||||
| babelConfig: babelLoader, | ||||||||||||||
| useLayers: true, | ||||||||||||||
| }, | ||||||||||||||
| ], | ||||||||||||||
| }, | ||||||||||||||
| }; | ||||||||||||||
| ``` | ||||||||||||||
|
|
||||||||||||||
| ## Vite configuration | ||||||||||||||
|
|
||||||||||||||
| If you just created a brand new Vite app, you might need to install | ||||||||||||||
|
|
||||||||||||||
| ``` | ||||||||||||||
| npm install vite-plugin-babel vite-tsconfig-paths | ||||||||||||||
| ``` | ||||||||||||||
|
|
||||||||||||||
| Create or edit the `vite.config.ts` file as follows. | ||||||||||||||
|
|
||||||||||||||
| ```js title="vite.config.ts" | ||||||||||||||
| import { defineConfig } from "vite"; | ||||||||||||||
| import viteBabel from "vite-plugin-babel"; | ||||||||||||||
| import viteReact from "@vitejs/plugin-react"; | ||||||||||||||
| import tsConfigPaths from "vite-tsconfig-paths"; | ||||||||||||||
| import viteReact from "@vitejs/plugin-react"; | ||||||||||||||
| import viteBabel from "vite-plugin-babel"; | ||||||||||||||
|
|
||||||||||||||
| export default defineConfig(() => ({ | ||||||||||||||
| plugins: [ | ||||||||||||||
|
|
@@ -92,7 +99,7 @@ export default defineConfig(() => ({ | |||||||||||||
|
|
||||||||||||||
| 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. | ||||||||||||||
|
|
||||||||||||||
| ```css title="strict.css" | ||||||||||||||
| ```css title="src/strict.css" | ||||||||||||||
| /* This directive is used by the react-strict-dom postcss plugin. */ | ||||||||||||||
| /* It is automatically replaced with generated CSS during builds. */ | ||||||||||||||
| @react-strict-dom; | ||||||||||||||
|
|
@@ -101,6 +108,8 @@ Your app needs to include a CSS file that contains a `@react-strict-dom` directi | |||||||||||||
| Next, import the CSS file in the `main.tsx` file. | ||||||||||||||
|
|
||||||||||||||
| ```js title="src/main.tsx" | ||||||||||||||
| // ... | ||||||||||||||
|
|
||||||||||||||
| // Required for CSS to work on Vite | ||||||||||||||
| import "./strict.css"; | ||||||||||||||
|
|
||||||||||||||
|
|
@@ -134,5 +143,21 @@ export default defineConfig(() => ({ | |||||||||||||
| ], | ||||||||||||||
| }, | ||||||||||||||
| })); | ||||||||||||||
| ``` | ||||||||||||||
|
|
||||||||||||||
| ## TanStack Start | ||||||||||||||
|
|
||||||||||||||
| If you plan to use TanStack Start, you will need to adjust your vite config with the `ssr` options | ||||||||||||||
|
Comment on lines
+148
to
+150
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this be generalized? Presumably the Vite ssr config is not just for TanStack
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure it can, I can ajust like that
Suggested change
|
||||||||||||||
|
|
||||||||||||||
| ```js title="vite.config.ts" | ||||||||||||||
| import { defineConfig } from "vite"; | ||||||||||||||
|
|
||||||||||||||
| //... | ||||||||||||||
|
|
||||||||||||||
| export default defineConfig(() => ({ | ||||||||||||||
| // ... | ||||||||||||||
| ssr: { | ||||||||||||||
| noExternal: ["react-strict-dom"], | ||||||||||||||
| }, | ||||||||||||||
| })); | ||||||||||||||
| ``` | ||||||||||||||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aren't plugins are supposed to be an array in the postcss config?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it support both format.