From 8db547052202ab3828efc7b533677ea1e762632c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8F=B2=E9=B8=BD?= <1020103647@qq.com> Date: Thu, 28 Mar 2024 17:39:01 +0800 Subject: [PATCH] build: add log --- tsconfig.json | 1 + vite-env.d.ts | 15 +++++++++++++++ vite.config.ts | 8 +++++--- 3 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 vite-env.d.ts diff --git a/tsconfig.json b/tsconfig.json index 64b345c..de074b7 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -13,6 +13,7 @@ "outDir": "dist", "lib": ["esnext", "dom"], "types": [ + "vite-env.d.ts", "@dcloudio/types", "@types/wechat-miniprogram", "@uni-helper/uni-app-types", diff --git a/vite-env.d.ts b/vite-env.d.ts new file mode 100644 index 0000000..ff5515b --- /dev/null +++ b/vite-env.d.ts @@ -0,0 +1,15 @@ +// 全局自定义参数 +declare const __UNI_PLATFORM__: + | 'h5' + | 'app' + | 'mp-alipay' + | 'mp-baidu' + | 'mp-jd' + | 'mp-kuaishou' + | 'mp-lark' + | 'mp-qq' + | 'mp-toutiao' + | 'mp-weixin' + | 'quickapp-webview' + | 'quickapp-webview-huawei' + | 'quickapp-webview-union' diff --git a/vite.config.ts b/vite.config.ts index 3bea96b..85a840f 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -35,7 +35,7 @@ export default ({ command, mode }) => { // console.log(mode === process.env.NODE_ENV) // true // mode: 区分生产环境还是开发环境 - console.log(command, mode) + console.log('command, mode -> ', command, mode) // pnpm dev:h5 时得到 => serve development // pnpm build:h5 时得到 => build production // pnpm dev:mp-weixin 时得到 => build development (注意区别,command为build) @@ -44,11 +44,13 @@ export default ({ command, mode }) => { // process.cwd(): 获取当前文件的目录跟地址 // loadEnv(): 返回当前环境env文件中额外定义的变量 const env = loadEnv(mode, path.resolve(process.cwd(), 'env')) - console.log(env) - console.log(process.env.UNI_PLATFORM) // 得到 mp-weixin, h5 等 + console.log('env -> ', env) + console.log('process.env.UNI_PLATFORM: ', process.env.UNI_PLATFORM) // 得到 mp-weixin, h5, app 等 + console.log('isH5: ', process.env.UNI_PLATFORM === 'h5') // 得到 mp-weixin, h5, app 等 return defineConfig({ envDir: './env', // 自定义env目录 + plugins: [ UniPages({ exclude: ['**/components/**/**.*'],