uniConfig.ts 1.7 KB
Newer Older
fxy060608's avatar
fxy060608 已提交
1 2 3 4 5 6 7 8 9
import { normalizeNetworkTimeout } from '../../manifest'
import {
  getNVueCompiler,
  getNVueFlexDirection,
  getNVueStyleCompiler,
} from '../manifest'

interface AppUniConfig {
  pages: string[]
fxy060608's avatar
fxy060608 已提交
10
  globalStyle: UniApp.PagesJsonPageStyle
fxy060608's avatar
fxy060608 已提交
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
  nvue: {
    compiler: 'uni-app' | 'weex'
    styleCompiler: 'weex' | 'uni-app'
    'flex-direction': 'row' | 'row-reverse' | 'column' | 'column-reverse'
  }
  renderer: 'auto' | 'native'
  splashscreen: {
    alwaysShowBeforeRender: boolean
    autoclose: boolean
  }
  appname: string
  compilerVersion: string
  entryPagePath: string
  networkTimeout: {
    request: number
    connectSocket: number
    uploadFile: number
    downloadFile: number
  }
fxy060608's avatar
fxy060608 已提交
30
  tabBar?: UniApp.UniConfig['tabBar']
fxy060608's avatar
fxy060608 已提交
31 32 33 34 35 36 37 38
}

export function normalizeAppUniConfig(
  pagesJson: UniApp.PagesJson,
  manifestJson: Record<string, any>
) {
  const config: AppUniConfig = {
    pages: [],
fxy060608's avatar
fxy060608 已提交
39
    globalStyle: pagesJson.globalStyle,
fxy060608's avatar
fxy060608 已提交
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
    nvue: {
      compiler: getNVueCompiler(manifestJson),
      styleCompiler: getNVueStyleCompiler(manifestJson),
      'flex-direction': getNVueFlexDirection(manifestJson),
    },
    renderer:
      manifestJson['app-plus']?.renderer === 'native' ? 'native' : 'auto',
    appname: manifestJson.name || '',
    splashscreen: {
      alwaysShowBeforeRender: process.env
        .UNI_SPLASHSCREEN_ALWAYSSHOWBEFORERENDER
        ? true
        : false,
      autoclose: process.env.UNI_SPLASHSCREEN_AUTOCLOSE ? true : false,
    },
    compilerVersion: process.env.UNI_COMPILER_VERSION,
fxy060608's avatar
fxy060608 已提交
56
    entryPagePath: pagesJson.pages[0].path,
fxy060608's avatar
fxy060608 已提交
57
    networkTimeout: normalizeNetworkTimeout(manifestJson.networkTimeout),
fxy060608's avatar
fxy060608 已提交
58
    tabBar: pagesJson.tabBar,
fxy060608's avatar
fxy060608 已提交
59
  }
fxy060608's avatar
fxy060608 已提交
60
  // TODO 待支持分包
fxy060608's avatar
fxy060608 已提交
61 62
  return JSON.stringify(config)
}