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
Copy file name to clipboardexpand all lines: docs/future/vite.md
+31-9
Original file line number
Diff line number
Diff line change
@@ -657,11 +657,34 @@ If a route's `links` function is only used to wire up `cssBundleHref`, you can r
657
657
- ];
658
658
```
659
659
660
-
#### Fix up CSS imports
660
+
#### Add `?url` to regular CSS imports
661
661
662
-
In Vite, CSS files are typically imported as side effects.
662
+
<docs-warning>
663
+
664
+
**This feature is not supported in Vite v5.0.x.**
665
+
666
+
Vite v5.0.x and earlier has a [known issue with `.css?url` imports][vite-css-url-issue] that causes them to break in production builds. If you'd like to use this feature immediately, support for `.css?url` imports is currently available in the [Vite v5.1.0 beta][vite-5-1-0-beta].
667
+
668
+
If you'd prefer to avoid running a beta version of Vite, you can either wait for Vite v5.1.0 or [convert your CSS imports to side-effects.](#optionally-convert-regular-css-imports-to-side-effect-imports)
663
669
664
-
During development, [Vite injects imported CSS files into the page via JavaScript,][vite-css] and the Remix Vite plugin will inline imported CSS alongside your link tags to avoid a flash of unstyled content. In the production build, the Remix Vite plugin will automatically attach CSS files to the relevant routes.
670
+
</docs-warning>
671
+
672
+
If you were using [Remix's regular CSS support][regular-css], you'll need to update your CSS import statements to use [Vite's explicit `?url` import syntax.][vite-url-imports]
673
+
674
+
👉 **Add `?url` to regular CSS imports**
675
+
676
+
```diff
677
+
-import styles from "~/styles/dashboard.css";
678
+
+import styles from "~/styles/dashboard.css?url";
679
+
```
680
+
681
+
#### Optionally convert regular CSS imports to side-effect imports
682
+
683
+
<docs-info>Any existing side-effect imports of CSS files in your Remix application will work in Vite without any code changes.</docs-info>
684
+
685
+
Rather than [migrating regular CSS imports to use Vite's explicit `.css?url` import syntax](#add-url-to-regular-css-imports) — which requires either waiting for Vite v5.1.0 or running the [v5.1.0 beta][vite-5-1-0-beta] — you can instead convert them to side-effect imports. You may even find that this approach is more convenient for you.
686
+
687
+
During development, [Vite injects CSS side-effect imports into the page via JavaScript,][vite-css] and the Remix Vite plugin will inline imported CSS alongside your link tags to avoid a flash of unstyled content. In the production build, the Remix Vite plugin will automatically attach CSS files to the relevant routes.
665
688
666
689
This also means that in many cases you won't need the `links` function export anymore.
667
690
@@ -672,10 +695,10 @@ Since the order of your CSS is determined by its import order, you'll need to en
672
695
```diff filename=app/dashboard/route.tsx
673
696
- import type { LinksFunction } from "@remix-run/node"; // or cloudflare/deno
674
697
675
-
- import dashboardStyles from "./dashboard.css?url";
676
-
- import sharedStyles from "./shared.css?url";
677
-
+ // ⚠️ NOTE: The import order has been updated
678
-
+ // to match the original `links` function!
698
+
- import dashboardStyles from "./dashboard.css";
699
+
- import sharedStyles from "./shared.css";
700
+
+ // NOTE: The import order has been updated
701
+
+ // to match the original `links` function.
679
702
+ import "./shared.css";
680
703
+ import "./dashboard.css";
681
704
@@ -685,8 +708,6 @@ Since the order of your CSS is determined by its import order, you'll need to en
685
708
- ];
686
709
```
687
710
688
-
<docs-warning>While [Vite supports importing static asset URLs via an explicit `?url` query string][vite-url-imports], which in theory would match the behavior of the existing Remix compiler when used for CSS files, there is a [known Vite issue with `?url` for CSS imports][vite-css-url-issue]. This may be fixed in the future, but in the meantime you should exclusively use side effect imports for CSS.</docs-warning>
689
-
690
711
#### Optionally scope regular CSS
691
712
692
713
If you were using [Remix's regular CSS support][regular-css], one important caveat to be aware of is that these styles will no longer be mounted and unmounted automatically when navigating between routes during development.
@@ -1256,3 +1277,4 @@ We're definitely late to the Vite party, but we're excited to be here now!
0 commit comments