Skip to content

Commit

Permalink
chore: improve Vite plugin migration path
Browse files Browse the repository at this point in the history
  • Loading branch information
Plopix committed Nov 3, 2023
1 parent 49d638b commit aeb53fd
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 12 deletions.
1 change: 1 addition & 0 deletions contributors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@
- phishy
- plastic041
- plondon
- plopix
- pmbanugo
- prasook-jain
- pratikdevdas
Expand Down
60 changes: 48 additions & 12 deletions docs/future/vite.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,23 +90,59 @@ Remix is now just a Vite plugin, so you'll need to hook it up to Vite.

```ts filename=vite.config.ts
import { unstable_vitePlugin as remix } from "@remix-run/dev";
import { defineConfig } from "vite";

export default defineConfig({
plugins: [remix()],
});
import tsconfigPaths from "vite-tsconfig-paths";
import { defineConfig, loadEnv } from "vite";

export default ({ mode }: { mode: string }) => {
const env = loadEnv(mode, process.cwd(), "");
process.env = { ...process.env, ...env };
return defineConfig({
plugins: [
remix(),
tsconfigPaths(),
],
});
};
```

The subset of [supported Remix config options][supported-remix-config-options] should be passed directly to the plugin:

```ts filename=vite.config.ts lines=[3-5]
export default defineConfig({
plugins: [
remix({
ignoredRouteFiles: ["**/.*"],
}),
],
});
export default ({ mode }: { mode: string }) => {
const env = loadEnv(mode, process.cwd(), "");
process.env = { ...process.env, ...env };
return defineConfig({
plugins: [
remix({
ignoredRouteFiles: ["**/.*"],
}),
tsconfigPaths(),
],
});
};
```

#### CSS Import

If you were importing file like this

```ts
import stylesheet from "~/styles/app.css";

export const links: LinksFunction = () => [
...(cssBundleHref ? [{ rel: "stylesheet", href: cssBundleHref }] : []),
{ rel: "stylesheet", href: stylesheet },
];
```

now you can just do this:

```ts
import "~/styles/app.css";

export const links: LinksFunction = () => [
...(cssBundleHref ? [{ rel: "stylesheet", href: cssBundleHref }] : []),
];
```

#### TypeScript integration
Expand Down

0 comments on commit aeb53fd

Please sign in to comment.