Skip to content

Commit

Permalink
feat: rn support dot env
Browse files Browse the repository at this point in the history
  • Loading branch information
zhiqingchen committed Jul 28, 2023
1 parent 7e428f4 commit 4f460f5
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/taro-rn-supporter/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as helper from '@tarojs/helper'
import { dotenvParse, patchEnv } from '@tarojs/helper'
import { Config } from '@tarojs/service'
import * as fs from 'fs'
import { networkInterfaces } from 'os'
Expand All @@ -11,13 +12,18 @@ let FROM_TARO = false

async function getProjectConfig () {
if (GLOBAL_CONFIG) return GLOBAL_CONFIG
const appPath = process.cwd()
const mode = process.env.NODE_ENV || 'development'
const config = new Config({
appPath: process.cwd()
appPath,
})
await config.init({
mode: process.env.NODE_ENV || 'development',
mode,
command: 'build'
})
// 这里解析 dotenv 以便于 config 解析时能获取 dotenv 配置信息
const expandEnv = dotenvParse(appPath, undefined, mode)
config.initialConfig.env = patchEnv(config.initialConfig, expandEnv)
GLOBAL_CONFIG = config.initialConfig
return GLOBAL_CONFIG
}
Expand Down

0 comments on commit 4f460f5

Please sign in to comment.