Skip to content

Commit

Permalink
Add nextjs env file handling to docs (#475)
Browse files Browse the repository at this point in the history
  • Loading branch information
zeekrey authored Aug 29, 2023
1 parent 0f864e3 commit 016a005
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions packages/website/docs/nextjs.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,20 @@ export default UnoptimizedImage;
```

This solution is inspired by [blog post](https://sdorra.dev/posts/2023-01-18-ladle-next-image#nextimage).

## Using environment variables

To make use of your current `.env` files, you simply need to let Vite know and ensure they are passed to the browser. As Next.js requires you to add `NEXT_PUBLIC_` as a prefix to your frontend environment variables, we also need to inform Vite about this.

To achieve this, you will need to customize Vite's configuration further.

```ts title="vite.config.ts"
import { defineConfig, loadEnv } from "vite";

export default defineConfig(({ mode }) => ({
// resolve: {...},
define: {
"process.env": loadEnv(mode, process.cwd(), "NEXT_PUBLIC_"),
},
}));
```

1 comment on commit 016a005

@vercel
Copy link

@vercel vercel bot commented on 016a005 Aug 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

ladle – ./

ladle-git-main-miksu.vercel.app
ladle-miksu.vercel.app
ladle.vercel.app
ladle.dev

Please sign in to comment.