You need to sign in or sign up before continuing.
env.js 16.5 KB
Newer Older
fxy060608's avatar
fxy060608 已提交
1
const fs = require('fs')
fxy060608's avatar
fxy060608 已提交
2
const path = require('path')
fxy060608's avatar
fxy060608 已提交
3
const mkdirp = require('mkdirp')
4
const loaderUtils = require('loader-utils')
fxy060608's avatar
fxy060608 已提交
5 6

require('./error-reporting')
fxy060608's avatar
fxy060608 已提交
7

8 9 10 11 12 13
const hasOwnProperty = Object.prototype.hasOwnProperty

function hasOwn (obj, key) {
  return hasOwnProperty.call(obj, key)
}

fxy060608's avatar
fxy060608 已提交
14 15 16 17 18
const defaultInputDir = 'src'
if (process.env.UNI_INPUT_DIR && process.env.UNI_INPUT_DIR.indexOf('./') === 0) {
  process.env.UNI_INPUT_DIR = path.resolve(process.cwd(), process.env.UNI_INPUT_DIR)
}
process.env.UNI_INPUT_DIR = process.env.UNI_INPUT_DIR || path.resolve(process.cwd(), defaultInputDir)
fxy060608's avatar
fxy060608 已提交
19 20 21 22 23 24 25 26 27 28

const manifestJsonObj = require('@dcloudio/uni-cli-shared/lib/manifest').getManifestJson()

// 小程序 vue3 标记
if (process.env.UNI_PLATFORM.indexOf('mp-') === 0) {
  if (manifestJsonObj.vueVersion === '3' || manifestJsonObj.vueVersion === 3) {
    process.env.UNI_USING_VUE3 = true
    process.env.UNI_USING_VUE3_OPTIONS_API = true
  }
}
fxy060608's avatar
fxy060608 已提交
29 30

// 初始化全局插件对象
fxy060608's avatar
fxy060608 已提交
31
global.uniPlugin = require('@dcloudio/uni-cli-shared/lib/plugin').init()
fxy060608's avatar
fxy060608 已提交
32

fxy060608's avatar
fxy060608 已提交
33 34 35 36 37 38
const platformOptions = manifestJsonObj[process.env.UNI_SUB_PLATFORM || process.env.UNI_PLATFORM] || {}
// 插件校验环境
global.uniPlugin.validate.forEach(validate => {
  validate(platformOptions, manifestJsonObj)
})
process.UNI_MANIFEST = manifestJsonObj
fxy060608's avatar
fxy060608 已提交
39

fxy060608's avatar
fxy060608 已提交
40 41
process.env.VUE_APP_NAME = manifestJsonObj.name

fxy060608's avatar
fxy060608 已提交
42
process.env.UNI_USING_V3_SCOPED = true
fxy060608's avatar
fxy060608 已提交
43

44
process.env.UNI_CLOUD_PROVIDER = JSON.stringify([])
fxy060608's avatar
fxy060608 已提交
45

46 47 48
const isH5 = !process.env.UNI_SUB_PLATFORM && process.env.UNI_PLATFORM === 'h5'
const isProduction = process.env.NODE_ENV === 'production'

fxy060608's avatar
fxy060608 已提交
49 50 51
if (process.env.UNI_CLOUD_SPACES) {
  try {
    const spaces = JSON.parse(process.env.UNI_CLOUD_SPACES)
fxy060608's avatar
fxy060608 已提交
52
    if (Array.isArray(spaces)) {
53
      const hasUniCloudSpace = spaces.length > 0
fxy060608's avatar
fxy060608 已提交
54
      if (spaces.length === 1) {
fxy060608's avatar
fxy060608 已提交
55
        const space = spaces[0]
56
        console.log(`本项目的uniCloud使用的默认服务空间spaceId为:${space.id}`)
fxy060608's avatar
fxy060608 已提交
57
      }
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75

      if (
        hasUniCloudSpace &&
        isH5 &&
        isProduction
      ) {
        console.warn(
          '发布H5,需要在uniCloud后台操作,绑定安全域名,否则会因为跨域问题而无法访问。教程参考:https://uniapp.dcloud.io/uniCloud/quickstart?id=useinh5')
      } else if (
        hasUniCloudSpace &&
        isH5 &&
        !isProduction
      ) {
        console.warn(
          '当前项目使用了uniCloud,为避免云函数调用跨域问题,建议在HBuilderX内置浏览器里调试,如使用外部浏览器需处理跨域,详见:https://uniapp.dcloud.io/uniCloud/quickstart?id=useinh5'
        )
      }

fxy060608's avatar
fxy060608 已提交
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
      process.env.UNI_CLOUD_PROVIDER = JSON.stringify(spaces.map(space => {
        if (space.clientSecret) {
          return {
            provider: 'aliyun',
            spaceName: space.name,
            spaceId: space.id,
            clientSecret: space.clientSecret,
            endpoint: space.apiEndpoint
          }
        } else {
          return {
            provider: 'tencent',
            spaceName: space.name,
            spaceId: space.id
          }
        }
92
      }))
fxy060608's avatar
fxy060608 已提交
93 94
    }
  } catch (e) {}
fxy060608's avatar
fxy060608 已提交
95
}
fxy060608's avatar
fxy060608 已提交
96

fxy060608's avatar
fxy060608 已提交
97 98 99
// 初始化环境变量
const defaultOutputDir = '../../../../dist/' +
  (process.env.NODE_ENV === 'production' ? 'build' : 'dev') + '/' +
fxy060608's avatar
fxy060608 已提交
100
  (process.env.UNI_SUB_PLATFORM || process.env.UNI_PLATFORM)
101

102
process.env.UNI_OUTPUT_DEFAULT_DIR = path.resolve(__dirname, defaultOutputDir)
fxy060608's avatar
fxy060608 已提交
103 104 105 106 107 108
if (process.env.UNI_OUTPUT_DIR && process.env.UNI_OUTPUT_DIR.indexOf('./') === 0) {
  process.env.UNI_OUTPUT_DIR = path.resolve(process.cwd(), process.env.UNI_OUTPUT_DIR)
}

process.env.UNI_PLATFORM = process.env.UNI_PLATFORM || 'h5'
process.env.VUE_APP_PLATFORM = process.env.UNI_PLATFORM
109
process.env.UNI_OUTPUT_DIR = process.env.UNI_OUTPUT_DIR || process.env.UNI_OUTPUT_DEFAULT_DIR
fxy060608's avatar
fxy060608 已提交
110 111 112 113 114 115 116 117 118

if (process.env.UNI_PLATFORM === 'app-plus') {
  process.env.UNI_OUTPUT_TMP_DIR = path.resolve(process.env.UNI_OUTPUT_DIR, '../.tmp/app-plus')
}

process.env.UNI_CLI_CONTEXT = path.resolve(__dirname, '../../../../')

process.UNI_LIBRARIES = process.UNI_LIBRARIES || ['@dcloudio/uni-ui']

fxy060608's avatar
fxy060608 已提交
119
if (process.env.NODE_ENV === 'production') { // 发行模式,不启用 cache
120
  delete process.env.UNI_USING_CACHE
fxy060608's avatar
fxy060608 已提交
121 122
}

fxy060608's avatar
fxy060608 已提交
123
const {
fxy060608's avatar
fxy060608 已提交
124
  normalizePath,
fxy060608's avatar
fxy060608 已提交
125 126
  isSupportSubPackages,
  runByHBuilderX,
fxy060608's avatar
fxy060608 已提交
127
  getPagesJson
128 129 130
} = require('@dcloudio/uni-cli-shared')

process.env.RUN_BY_HBUILDERX = JSON.stringify(runByHBuilderX)
131 132 133 134 135 136

const {
  initUniModules
} = require('@dcloudio/uni-cli-shared/lib/uni_modules')

initUniModules()
fxy060608's avatar
fxy060608 已提交
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157

const pagesJsonObj = getPagesJson()
// 读取分包
process.UNI_SUBPACKAGES = {}
if (Array.isArray(pagesJsonObj.subPackages)) {
  pagesJsonObj.subPackages.forEach(subPackage => {
    if (subPackage && subPackage.root) {
      const {
        name,
        root,
        independent
      } = subPackage
      process.UNI_SUBPACKAGES[root] = {
        name,
        root,
        independent
      }
    }
  })
}

fxy060608's avatar
fxy060608 已提交
158 159
process.UNI_PAGES = pagesJsonObj

fxy060608's avatar
fxy060608 已提交
160 161 162 163 164 165 166 167
if (manifestJsonObj.debug) {
  process.env.VUE_APP_DEBUG = true
}

process.UNI_STAT_CONFIG = {
  appid: manifestJsonObj.appid
}

168 169
// 默认启用 自定义组件模式
// if (isInHBuilderXAlpha) {
170
let usingComponentsAbsent = false
171
if (!hasOwn(platformOptions, 'usingComponents')) {
172
  usingComponentsAbsent = true
173
}
fxy060608's avatar
fxy060608 已提交
174
platformOptions.usingComponents = true
175
// }
fxy060608's avatar
fxy060608 已提交
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205

if (process.env.UNI_PLATFORM === 'h5') {
  const optimization = platformOptions.optimization
  if (optimization) {
    // 发行模式且主动启用优化
    const treeShaking = optimization.treeShaking
    if (
      treeShaking &&
      treeShaking.enable &&
      process.env.NODE_ENV === 'production'
    ) {
      process.env.UNI_OPT_TREESHAKINGNG = true
      process.UNI_USER_APIS = new Set()
      if (Array.isArray(treeShaking.modules) && treeShaking.modules.length) {
        const {
          parseUserApis
        } = require('@dcloudio/uni-cli-shared/lib/api')
        try {
          const modules = require('@dcloudio/uni-h5/lib/modules.json')
          process.UNI_USER_APIS = parseUserApis(treeShaking.modules || [], modules)
        } catch (e) {}
      }
    }
    if (optimization.prefetch) {
      process.env.UNI_OPT_PREFETCH = true
    }
    if (optimization.preload) {
      process.env.UNI_OPT_PRELOAD = true
    }
  }
206 207
  const buffer = fs.readFileSync(require.resolve('@dcloudio/uni-h5/dist/index.css'))
  process.env.VUE_APP_INDEX_CSS_HASH = loaderUtils.getHashDigest(buffer, 'md5', 'hex', 8)
fxy060608's avatar
fxy060608 已提交
208 209 210 211 212 213
}

if (process.env.UNI_PLATFORM === 'mp-qq') { // QQ小程序 强制自定义组件模式
  platformOptions.usingComponents = true
}

214
let isNVueCompiler = true
fxy060608's avatar
fxy060608 已提交
215
if (process.env.UNI_PLATFORM === 'app-plus') {
216 217
  if (platformOptions.nvueCompiler === 'weex') {
    isNVueCompiler = false
fxy060608's avatar
fxy060608 已提交
218
  }
fxy060608's avatar
fxy060608 已提交
219 220 221 222 223 224 225

  delete process.env.UNI_USING_CACHE
  if (platformOptions.renderer === 'native') {
    process.env.UNI_USING_V3_NATIVE = true
  } else {
    process.env.UNI_USING_V3 = true
    platformOptions.usingComponents = true
fxy060608's avatar
fxy060608 已提交
226
  }
fxy060608's avatar
fxy060608 已提交
227 228 229
  process.env.UNI_OUTPUT_TMP_DIR = ''
  // isNVueCompiler = true // v3 目前仅支持 uni-app 模式

fxy060608's avatar
fxy060608 已提交
230 231 232 233 234 235 236 237 238 239 240 241 242 243
  // v3 支持指定 js 混淆(仅发行模式)
  if (
    process.env.NODE_ENV === 'production' &&
    process.env.UNI_USING_V3
  ) {
    const resources = platformOptions.confusion &&
      platformOptions.confusion.resources
    const resourcesKeys = resources &&
      Object.keys(resources).filter(filepath => path.extname(filepath) === '.js')
    if (resourcesKeys && resourcesKeys.length) {
      process.UNI_CONFUSION = resourcesKeys.map(filepath =>
        normalizePath(path.resolve(process.env.UNI_INPUT_DIR, filepath))
      )
    }
fxy060608's avatar
fxy060608 已提交
244
  }
fxy060608's avatar
fxy060608 已提交
245 246 247
} else { // 其他平台,待确认配置方案
  if (
    manifestJsonObj['app-plus'] &&
fxy060608's avatar
fxy060608 已提交
248
    manifestJsonObj['app-plus'].nvueCompiler === 'weex'
fxy060608's avatar
fxy060608 已提交
249
  ) {
250
    isNVueCompiler = false
fxy060608's avatar
fxy060608 已提交
251 252 253 254 255 256 257
  }
}

if (isNVueCompiler) {
  process.env.UNI_USING_NVUE_COMPILER = true
}

258
if (platformOptions.nvueStyleCompiler === 'uni-app') {
259
  process.env.UNI_USING_NVUE_STYLE_COMPILER = true
260 261
} else {
  platformOptions.nvueStyleCompiler = 'weex'
262 263
}

fxy060608's avatar
fxy060608 已提交
264 265 266 267 268 269 270 271 272
if (platformOptions.usingComponents === true) {
  if (process.env.UNI_PLATFORM !== 'h5') {
    process.env.UNI_USING_COMPONENTS = true
  }
  if (process.env.UNI_PLATFORM === 'app-plus') {
    process.env.UNI_USING_V8 = true
  }
}

273 274
// 兼容历史配置 betterScopedSlots
const modes = ['legacy', 'auto', 'augmented']
fxy060608's avatar
fxy060608 已提交
275 276
const scopedSlotsCompiler = !platformOptions.scopedSlotsCompiler && platformOptions.betterScopedSlots ? modes[2]
  : platformOptions.scopedSlotsCompiler
277
process.env.SCOPED_SLOTS_COMPILER = modes.includes(scopedSlotsCompiler) ? scopedSlotsCompiler : modes[1]
278 279 280 281
// 快手小程序抽象组件编译报错,如未指定 legacy 固定为 augmented 模式
if (process.env.UNI_PLATFORM === 'mp-kuaishou' && process.env.SCOPED_SLOTS_COMPILER !== modes[0]) {
  process.env.SCOPED_SLOTS_COMPILER = modes[2]
}
Q
qiang 已提交
282 283 284 285
// Vue3 暂时固定为 legacy 模式
if (process.env.UNI_USING_VUE3) {
  process.env.SCOPED_SLOTS_COMPILER = modes[0]
}
286

fxy060608's avatar
fxy060608 已提交
287
if (
288 289
  process.env.UNI_USING_COMPONENTS ||
  process.env.UNI_PLATFORM === 'h5'
fxy060608's avatar
fxy060608 已提交
290
) { // 自定义组件模式或 h5 平台
291 292 293 294 295
  const uniStatistics = Object.assign(
    manifestJsonObj.uniStatistics || {},
    platformOptions.uniStatistics || {}
  )

fxy060608's avatar
fxy060608 已提交
296
  if (uniStatistics.enable === true) {
297 298
    process.env.UNI_USING_STAT = true
    if (!process.UNI_STAT_CONFIG.appid && process.env.NODE_ENV === 'production') {
299
      console.log()
fxy060608's avatar
fxy060608 已提交
300
      console.warn('当前应用未配置Appid,无法使用uni统计,详情参考:https://ask.dcloud.net.cn/article/36303')
301 302 303 304 305
      console.log()
    }
  }
}

fxy060608's avatar
fxy060608 已提交
306 307 308 309 310 311 312 313 314
if (process.env.UNI_USING_COMPONENTS) { // 是否启用分包优化
  if (platformOptions.optimization) {
    if (
      isSupportSubPackages() &&
      platformOptions.optimization.subPackages &&
      Object.keys(process.UNI_SUBPACKAGES).length
    ) {
      process.env.UNI_OPT_SUBPACKAGES = true
    }
fxy060608's avatar
fxy060608 已提交
315 316
  }
}
317

318 319
const warningMsg =
  usingComponentsAbsent
fxy060608's avatar
fxy060608 已提交
320 321
    ? '该应用之前可能是非自定义组件模式,目前以自定义组件模式运行。非自定义组件已于2019年11月1日起停止支持。详见:https://ask.dcloud.net.cn/article/36385'
    : 'uni-app已于2019年11月1日起停止支持非自定义组件模式 [详情](https://ask.dcloud.net.cn/article/36385)'
322 323

const needWarning = !platformOptions.usingComponents || usingComponentsAbsent
fxy060608's avatar
fxy060608 已提交
324
let hasNVue = false
fxy060608's avatar
fxy060608 已提交
325
// 输出编译器版本等信息
fxy060608's avatar
fxy060608 已提交
326
if (process.env.UNI_USING_NATIVE || process.env.UNI_USING_V3_NATIVE) {
fxy060608's avatar
fxy060608 已提交
327 328
  console.log('当前nvue编译模式' + (process.env.UNI_USING_V3_NATIVE ? '(v3)' : '') + '' + (isNVueCompiler ? 'uni-app'
    : 'weex') +
fxy060608's avatar
fxy060608 已提交
329
    ' 。编译模式差异见:https://ask.dcloud.net.cn/article/36074')
fxy060608's avatar
fxy060608 已提交
330
} else if (process.env.UNI_PLATFORM !== 'h5' && process.env.UNI_PLATFORM !== 'quickapp-native') {
fxy060608's avatar
fxy060608 已提交
331 332 333 334 335
  try {
    let info = ''
    if (process.env.UNI_PLATFORM === 'app-plus') {
      const pagesPkg = require('@dcloudio/webpack-uni-pages-loader/package.json')
      if (pagesPkg) {
fxy060608's avatar
fxy060608 已提交
336 337
        const v3Tips = '(v3)详见:https://ask.dcloud.net.cn/article/36599。'
        info = '编译器版本:' + pagesPkg['uni-app'].compilerVersion + (process.env.UNI_USING_V3 ? v3Tips : '')
fxy060608's avatar
fxy060608 已提交
338
      }
fxy060608's avatar
fxy060608 已提交
339 340 341
      if (process.env.UNI_USING_V3) {
        console.log(info)
      } else {
fxy060608's avatar
fxy060608 已提交
342 343 344 345 346 347 348 349 350 351 352 353
        const glob = require('glob')
        hasNVue = !!glob.sync('pages/**/*.nvue', {
          cwd: process.env.UNI_INPUT_DIR
        }).length
        if (hasNVue) {
          console.log(info)
          if (needWarning) {
            console.log(warningMsg)
          }
          console.log('当前nvue编译模式:' + (isNVueCompiler ? 'uni-app' : 'weex') +
            ' 。编译模式差异见:https://ask.dcloud.net.cn/article/36074')
        } else {
354
          console.log(info)
fxy060608's avatar
fxy060608 已提交
355 356 357
          if (needWarning) {
            console.log(warningMsg)
          }
358
        }
fxy060608's avatar
fxy060608 已提交
359 360
      }
    } else {
361
      if (needWarning) {
362
        console.log(warningMsg)
363
      }
fxy060608's avatar
fxy060608 已提交
364 365 366
    }
  } catch (e) {}
}
fxy060608's avatar
fxy060608 已提交
367
if (process.env.NODE_ENV !== 'production') { // 运行模式性能提示
fxy060608's avatar
fxy060608 已提交
368
  let perfMsg = '请注意运行模式下,因日志输出、sourcemap以及未压缩源码等原因,性能和包体积,均不及发行模式。'
fxy060608's avatar
fxy060608 已提交
369
  if (hasNVue) { // app-nvue
fxy060608's avatar
fxy060608 已提交
370
    perfMsg = perfMsg + '尤其是app-nvue的sourcemap影响较大'
fxy060608's avatar
fxy060608 已提交
371
  } else if (process.env.UNI_PLATFORM.indexOf('mp-') === 0) { // 小程序
fxy060608's avatar
fxy060608 已提交
372
    perfMsg = perfMsg + '若要正式发布,请点击发行菜单或使用cli发布命令进行发布'
fxy060608's avatar
fxy060608 已提交
373 374 375
  }
  console.log(perfMsg)
}
fxy060608's avatar
fxy060608 已提交
376 377 378

const moduleAlias = require('module-alias')

379
// 将 template-compiler 指向修订后的版本
fxy060608's avatar
fxy060608 已提交
380
moduleAlias.addAlias('vue-template-compiler', '@dcloudio/vue-cli-plugin-uni/packages/vue-template-compiler')
fxy060608's avatar
fxy060608 已提交
381
moduleAlias.addAlias('@megalo/template-compiler', '@dcloudio/vue-cli-plugin-uni/packages/@megalo/template-compiler')
382
moduleAlias.addAlias('mpvue-template-compiler', '@dcloudio/vue-cli-plugin-uni/packages/mpvue-template-compiler')
383 384
// vue-loader
moduleAlias.addAlias('vue-loader', '@dcloudio/vue-cli-plugin-uni/packages/vue-loader')
fxy060608's avatar
fxy060608 已提交
385

fxy060608's avatar
fxy060608 已提交
386 387
if (process.env.UNI_USING_V3 && process.env.UNI_PLATFORM === 'app-plus') {
  moduleAlias.addAlias('./runtime/getUrl.js', '@dcloudio/vue-cli-plugin-uni/lib/app-plus/getUrl.js')
fxy060608's avatar
fxy060608 已提交
388
  moduleAlias.addAlias('../runtime/getUrl.js', '@dcloudio/vue-cli-plugin-uni/lib/app-plus/getUrl.js')
fxy060608's avatar
fxy060608 已提交
389
  moduleAlias.addAlias('vue-style-loader', '@dcloudio/vue-cli-plugin-uni/packages/app-vue-style-loader')
390
}
fxy060608's avatar
fxy060608 已提交
391

Q
qiang 已提交
392 393 394
if (process.env.UNI_PLATFORM === 'h5') {
  moduleAlias.addAlias('vue-style-loader', '@dcloudio/vue-cli-plugin-uni/packages/h5-vue-style-loader')
}
fxy060608's avatar
fxy060608 已提交
395

fxy060608's avatar
fxy060608 已提交
396
if (process.env.UNI_PLATFORM === 'mp-toutiao') {
397 398 399 400 401 402 403
  // !important 始终带有一个空格
  moduleAlias.addAlias(
    'postcss-normalize-whitespace',
    '@dcloudio/vue-cli-plugin-uni/packages/postcss-normalize-whitespace'
  )
}

fxy060608's avatar
fxy060608 已提交
404 405 406 407 408 409 410 411 412 413 414 415 416 417 418
if (runByHBuilderX) {
  const oldError = console.error
  console.error = function (msg) {
    if (typeof msg === 'string' && msg.includes(
      '[BABEL] Note: The code generator has deoptimised the styling of')) {
      const filePath = msg.replace('[BABEL] Note: The code generator has deoptimised the styling of ', '').split(
        ' as ')[0]
      console.log('[警告] `' + path.relative(process.env.UNI_INPUT_DIR, filePath) +
        '` 文件体积超过 500KB,已跳过压缩以及 ES6 转 ES5 的处理,手机端使用过大的js库影响性能。')
    } else {
      oldError.apply(console, arguments)
      // TODO 如果是首次运行遇到错误直接退出
    }
  }
}
419

fxy060608's avatar
fxy060608 已提交
420 421
if (
  process.env.UNI_USING_CACHE &&
fxy060608's avatar
fxy060608 已提交
422
  process.env.UNI_PLATFORM !== 'h5' &&
fxy060608's avatar
fxy060608 已提交
423
  !process.env.UNI_USING_V3 &&
fxy060608's avatar
fxy060608 已提交
424 425
  !process.env.UNI_USING_NATIVE &&
  !process.env.UNI_USING_V3_NATIVE
fxy060608's avatar
fxy060608 已提交
426 427
) { // 使用 cache, 拷贝 cache 的 json
  const cacheJsonDir = path.resolve(
fxy060608's avatar
fxy060608 已提交
428
    process.env.UNI_CLI_CONTEXT,
fxy060608's avatar
fxy060608 已提交
429
    'node_modules/.cache/uni-pages-loader/' + process.env.UNI_PLATFORM
fxy060608's avatar
fxy060608 已提交
430 431 432 433
  )
  if (!fs.existsSync(cacheJsonDir)) { //  创建 cache 目录
    mkdirp(cacheJsonDir)
  } else {
fxy060608's avatar
fxy060608 已提交
434
    require('@dcloudio/uni-cli-shared/lib/cache').restore()
fxy060608's avatar
fxy060608 已提交
435 436 437
  }
}

438
const {
439
  initAutoImportComponents,
fxy060608's avatar
fxy060608 已提交
440
  initAutoImportScanComponents
441 442 443 444 445 446 447
} = require('@dcloudio/uni-cli-shared/lib/pages')

process.UNI_AUTO_SCAN_COMPONENTS = !(pagesJsonObj.easycom && pagesJsonObj.easycom.autoscan === false)
initAutoImportComponents(pagesJsonObj.easycom)
if (process.UNI_AUTO_SCAN_COMPONENTS) {
  initAutoImportScanComponents()
}
448

fxy060608's avatar
fxy060608 已提交
449 450 451 452
global.uniPlugin.configureEnv.forEach(configureEnv => {
  configureEnv()
})

fxy060608's avatar
fxy060608 已提交
453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473
if (
  process.env.UNI_PLATFORM === 'h5' ||
  (
    process.env.UNI_PLATFORM === 'app-plus' &&
    process.env.UNI_USING_V3
  )
) {
  const migrate = require('@dcloudio/uni-migration')
  const wxcomponentDirs = [path.resolve(process.env.UNI_INPUT_DIR, 'wxcomponents')]
  global.uniModules.forEach(module => {
    wxcomponentDirs.push(path.resolve(process.env.UNI_INPUT_DIR, 'uni_modules', module, 'wxcomponents'))
  })
  wxcomponentDirs.forEach(wxcomponentsDir => {
    if (fs.existsSync(wxcomponentsDir)) { // 转换 mp-weixin 小程序组件
      migrate(wxcomponentsDir, false, {
        silent: true // 不输出日志
      })
    }
  })
}

fxy060608's avatar
fxy060608 已提交
474 475 476 477
if (process.env.UNI_PLATFORM.startsWith('mp-')) {
  console.log('小程序各家浏览器内核及自定义组件实现机制存在差异,可能存在样式布局兼容问题,参考:https://uniapp.dcloud.io/matter?id=mp')
}

fxy060608's avatar
fxy060608 已提交
478
runByHBuilderX && console.log('正在编译中...')
fxy060608's avatar
fxy060608 已提交
479 480 481

module.exports = {
  manifestPlatformOptions: platformOptions
fxy060608's avatar
fxy060608 已提交
482
}