index.js 1.1 KB
Newer Older
fxy060608's avatar
fxy060608 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
const {
  manifestPlatformOptions
} = require('./lib/env')

const {
  assetsDir
} = require('./lib/copy-webpack-options')

require('./lib/check-update')()

const initBuildCommand = require('./commands/build')
const initServeCommand = require('./commands/serve')

module.exports = (api, options) => {
  initServeCommand(api, options)

  initBuildCommand(api, options)

  const platformOptions = require('./lib/' + process.env.UNI_PLATFORM)
fxy060608's avatar
fxy060608 已提交
20 21 22 23 24 25

  let vueConfig = platformOptions.vueConfig

  if (typeof vueConfig === 'function') {
    vueConfig = vueConfig(options, api)
  }
fxy060608's avatar
fxy060608 已提交
26

fxy060608's avatar
fxy060608 已提交
27
  Object.assign(options, { // TODO 考虑非 HBuilderX 运行时,可以支持自定义输出目录
fxy060608's avatar
fxy060608 已提交
28 29
    outputDir: process.env.UNI_OUTPUT_TMP_DIR || process.env.UNI_OUTPUT_DIR,
    assetsDir
fxy060608's avatar
fxy060608 已提交
30
  }, vueConfig)
fxy060608's avatar
fxy060608 已提交
31 32 33

  require('./lib/options')(options)

fxy060608's avatar
fxy060608 已提交
34
  api.configureWebpack(require('./lib/configure-webpack')(platformOptions, manifestPlatformOptions, options, api))
fxy060608's avatar
fxy060608 已提交
35
  api.chainWebpack(require('./lib/chain-webpack')(platformOptions, options, api))
fxy060608's avatar
fxy060608 已提交
36 37 38
}

module.exports.defaultModes = {
fxy060608's avatar
fxy060608 已提交
39 40
  'uni-serve': 'development',
  'uni-build': process.env.NODE_ENV
fxy060608's avatar
fxy060608 已提交
41
}