Quellcode durchsuchen

feat(manifest): 读取env 配置

Burt vor 2 Jahren
Ursprung
Commit
6a582f0a57
4 geänderte Dateien mit 15 neuen und 8 gelöschten Zeilen
  1. 2 2
      env/.env
  2. 8 3
      manifest.config.ts
  3. 3 3
      src/manifest.json
  4. 2 0
      vite.config.ts

+ 2 - 2
env/.env

@@ -1,5 +1,5 @@
-VITE_APP_TITLE = 'vue3-uniapp'
+VITE_APP_TITLE = 'unifly-uniapp'
 VITE_APP_PORT = 9000
 
-VIRW_UNI_APPID = 'H5871D791'
+VITE_UNI_APPID = 'H5871D791'
 VITE_WX_APPID = 'wxa2abb91f64032a2b'

+ 8 - 3
manifest.config.ts

@@ -1,9 +1,14 @@
 // manifest.config.ts
 import { defineManifestConfig } from '@uni-helper/vite-plugin-uni-manifest'
+import path from 'node:path'
+import { loadEnv } from 'vite'
 
+const env = loadEnv(process.env.NODE_ENV!, path.resolve(process.cwd(), 'env'))
+// console.log(env)
+const { VITE_APP_TITLE, VITE_UNI_APPID, VITE_WX_APPID } = env
 export default defineManifestConfig({
-  name: 'unifly',
-  appid: '',
+  name: VITE_APP_TITLE,
+  appid: VITE_UNI_APPID,
   description: '',
   versionName: '1.0.0',
   versionCode: '100',
@@ -61,7 +66,7 @@ export default defineManifestConfig({
   quickapp: {},
   /* 小程序特有相关 */
   'mp-weixin': {
-    appid: '',
+    appid: VITE_WX_APPID,
     setting: {
       urlCheck: false,
     },

+ 3 - 3
src/manifest.json

@@ -1,6 +1,6 @@
 {
-  "name": "unifly",
-  "appid": "",
+  "name": "unifly-uniapp",
+  "appid": "H5871D791",
   "description": "",
   "versionName": "1.0.0",
   "versionCode": "100",
@@ -46,7 +46,7 @@
   },
   "quickapp": {},
   "mp-weixin": {
-    "appid": "",
+    "appid": "wxa2abb91f64032a2b",
     "setting": {
       "urlCheck": false
     },

+ 2 - 0
vite.config.ts

@@ -23,6 +23,8 @@ import autoprefixer from 'autoprefixer'
 
 // https://vitejs.dev/config/
 export default ({ command, mode }) => {
+  console.log(mode === process.env.NODE_ENV)
+
   // mode: 区分生产环境还是开发环境
   console.log(command, mode)
   // pnpm dev:h5 时得到 => serve development