Skip to content

Commit

Permalink
build: add log
Browse files Browse the repository at this point in the history
  • Loading branch information
feige996 committed Mar 28, 2024
1 parent 78cb98f commit 5cfca40
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"outDir": "dist",
"lib": ["esnext", "dom"],
"types": [
"vite-env.d.ts",
"@dcloudio/types",
"@types/wechat-miniprogram",
"@uni-helper/uni-app-types",
Expand Down
15 changes: 15 additions & 0 deletions vite-env.d.ts
Original file line number Diff line number Diff line change
@@ -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'
8 changes: 5 additions & 3 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ export default ({ command, mode }) => {
// console.log(mode === process.env.NODE_ENV) // true

// mode: 区分生产环境还是开发环境
console.log(process.env.UNI_PLATFORM) // 得到 mp-weixin, h5 等
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)
Expand All @@ -43,10 +42,13 @@ export default ({ command, mode }) => {
// process.cwd(): 获取当前文件的目录跟地址
// loadEnv(): 返回当前环境env文件中额外定义的变量
const env = loadEnv(mode, path.resolve(process.cwd(), 'env'))
console.log(env)
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/**/**.*', '**/my/**/**.vue'],
Expand Down

0 comments on commit 5cfca40

Please sign in to comment.