Skip to content

Commit

Permalink
add config
Browse files Browse the repository at this point in the history
  • Loading branch information
houko committed Apr 4, 2024
1 parent 3d6299b commit 303d589
Show file tree
Hide file tree
Showing 8 changed files with 1,231 additions and 2,324 deletions.
2 changes: 2 additions & 0 deletions .env.development
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
BASE_URL=/
API_BASE_URL=https://api.beta.example.com
2 changes: 2 additions & 0 deletions .env.production
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
BASE_URL=/nuxt-flowbite-samples/
API_BASE_URL=https://api.example.com
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,4 @@ logs

# Local env files
.env
.env.*
!.env.example
1,017 changes: 1,017 additions & 0 deletions components/nav.vue

Large diffs are not rendered by default.

11 changes: 9 additions & 2 deletions nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,16 @@
// export default defineNuxtConfig({
export default defineNuxtConfig({
devtools: { enabled: true },
runtimeConfig: {
public: {
BASE_URL: process.env.BASE_URL, // 客户端和服务器端都可访问
API_BASE_URL: process.env.API_BASE_URL,
},
// 私有配置项只能在服务器端访问
secretKey: process.env.SECRET_KEY,
},
app: {
baseURL: '/nuxt-flowbite-samples/', // baseURL: '/<repository>/'
baseURL: process.env.BASE_URL || '', // baseURL: '/<repository>/'
buildAssetsDir: 'assets', // don't use "_" at the begining of the folder name to avoids nojkill conflict
},
modules: [
Expand All @@ -17,7 +25,6 @@ export default defineNuxtConfig({
"@formkit/auto-animate",
"@nuxt/image",
"nuxt-icon",
"@vite-pwa/nuxt",
"@formkit/nuxt"
]
})
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
"build": "nuxt build",
"dev": "nuxt dev",
"generate": "nuxt generate",
"deploy":"nuxt build && nuxt generate",
"preview": "nuxt preview",
"postinstall": "nuxt prepare"
"deploy": "nuxt build && nuxt generate",
"preview": "npm run clean && npm run build && nuxt preview",
"postinstall": "nuxt prepare",
"clean": "rimraf .nuxt .output dist"
},
"dependencies": {
"flowbite": "^2.3.0",
Expand All @@ -25,10 +26,9 @@
"@nuxtjs/tailwindcss": "^6.11.4",
"@pinia-plugin-persistedstate/nuxt": "^1.2.0",
"@pinia/nuxt": "^0.5.1",
"@vite-pwa/nuxt": "^0.6.0",
"@vueuse/nuxt": "^10.9.0",
"nuxt-gtag": "^2.0.5",
"nuxt-icon": "^0.6.10",
"nuxt-primevue": "^0.3.1"
"rimraf": "^5.0.5"
}
}
10 changes: 6 additions & 4 deletions pages/index.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<script setup lang="ts">
import hero from "~/components/hero.vue";
import modal from "~/components/modal.vue";
import nav from "~/components/nav.vue";
const config = useRuntimeConfig();
console.log(config.public.API_BASE_URL); // 访问公开的环境变量
</script>

<template>
<hero></hero>
<modal></modal>
aaa
<nav></nav>
</template>
Loading

0 comments on commit 303d589

Please sign in to comment.