Skip to content
Discussion options

You must be logged in to vote

Ok, I figured out a solution. Install the Vite plugin vite-env-only by @pcattori.

npm install vite-env-only

Update your vite.config.ts file to add the plugin.

// vite.config.ts
import envOnly from "vite-env-only";

export default defineConfig({
  plugins: [envOnly(), remix(), tsconfigPaths()],
});

Export your checkEnv function

// env.server.ts
export const checkEnv = () => {
  console.log("checking env");
};

Then in your root, import the function and wrap in serverOnly$ call

// root.tsx
import { serverOnly$ } from "vite-env-only";
import { checkEnv } from "./env.server";
serverOnly$(checkEnv());

This will call checkEnv() at startup for production builds, and on first route access for deve…

Replies: 2 comments 10 replies

Comment options

You must be logged in to vote
8 replies
@maranomynet
Comment options

@maranomynet
Comment options

@maranomynet
Comment options

@kiliman
Comment options

Answer selected by maranomynet
@maranomynet
Comment options

@davidsonsns
Comment options

Comment options

You must be logged in to vote
2 replies
@gustavopch
Comment options

@maranomynet
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
5 participants