Skip to content

Commit

Permalink
✨ setup env
Browse files Browse the repository at this point in the history
  • Loading branch information
w3cj committed Sep 12, 2024
1 parent b1934f4 commit 658d51e
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"extends": ["next/core-web-vitals", "next/typescript", "prettier"],
"plugins": ["check-file"],
"plugins": ["check-file", "n"],
"rules": {
"prefer-arrow-callback": ["error"],
"prefer-template": ["error"],
"semi": ["error"],
"quotes": ["error", "double"],
"n/no-process-env": ["error"],
"check-file/filename-naming-convention": [
"error",
{
Expand Down
7 changes: 7 additions & 0 deletions next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
import createJiti from "jiti";
import { fileURLToPath } from "node:url";

const jiti = createJiti(fileURLToPath(import.meta.url));

jiti("./src/env/server.ts");

/** @type {import('next').NextConfig} */
const nextConfig = {
experimental: {
Expand Down
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@
},
"dependencies": {
"@nextui-org/react": "^2.4.6",
"@t3-oss/env-nextjs": "^0.11.1",
"@tabler/icons-react": "^3.16.0",
"framer-motion": "^11.5.4",
"jiti": "^1.21.6",
"next": "14.2.9",
"next-themes": "^0.3.0",
"react": "^18",
"react-dom": "^18"
"react-dom": "^18",
"zod": "^3.23.8"
},
"devDependencies": {
"@trivago/prettier-plugin-sort-imports": "^4.3.0",
Expand All @@ -27,6 +30,7 @@
"eslint-config-next": "14.2.9",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-check-file": "^2.8.0",
"eslint-plugin-n": "^17.10.2",
"postcss": "^8",
"prettier": "3.3.3",
"prettier-plugin-tailwindcss": "^0.6.6",
Expand Down
96 changes: 96 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions src/env/server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { createEnv } from "@t3-oss/env-nextjs";
import { ZodError, z } from "zod";

export const env = createEnv({
server: {
NODE_ENV: z.enum(["development", "production"]),
},
onValidationError: (error: ZodError) => {
console.error(
"❌ Invalid environment variables:",
error.flatten().fieldErrors
);
process.exit(1);
},
emptyStringAsUndefined: true,
// eslint-disable-next-line n/no-process-env
experimental__runtimeEnv: process.env,
});

0 comments on commit 658d51e

Please sign in to comment.