Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ env ] .env 設定相關 #3

Open
veraaaaaLiu opened this issue Feb 22, 2024 · 0 comments
Open

[ env ] .env 設定相關 #3

veraaaaaLiu opened this issue Feb 22, 2024 · 0 comments

Comments

@veraaaaaLiu
Copy link
Owner

veraaaaaLiu commented Feb 22, 2024

Screenshot 2024-02-22 at 8 14 38 PM

為了使根目錄乾淨,.env 可以放進 env 的資料夾

如圖的 .env 分為三個,.env 是全部環境共用的 env 檔案,.env.development 是測試機專用的,.env.production 則是正式機,
但其實還可以多個 .env.staging ,是 for 上測試後但還未發正式機的情況,他可能是 beta- 之類的,也會跟正式和測試有區別。


只在本地有效的變量 .env.local

有時候你可能有一些不應該提交到程式碼倉庫中的變數。
這種情況下你應該使用一個 .env.local 檔案取而代之。本地環境檔案預設會被忽略,且出現在 .gitignore 中。
.local 也可以加在指定模式的環境檔案上,比如 .env.development.local 將會在 development 模式下被載入,且被 git 忽略。


nuxt3 - 1

// nuxt.config.ts
import { resolve } from "path";

const pathResolve = (dir: string) => {
  return resolve(__dirname, dir);
}

export default defineNuxtConfig({
  vite: {
    envDir: pathResolve('./env'),
  },
});

nuxt3 - 2

// .env
COOKIE_NAME=__session
COOKIE_SECRET=superdupersecret
// nuxt.config.ts
export default defineNuxtConfig({
   runtimeConfig: {
      cookieName: process.env.COOKIE_NAME || "__session",
      cookieSecret: process.env.COOKIE_SECRET || "secret",
    },
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant