index.js 1.0 KB
Newer Older
fxy060608's avatar
fxy060608 已提交
1 2 3 4 5 6 7 8
const fs = require('fs')
const path = require('path')

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

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

require('./module-alias')
fxy060608's avatar
fxy060608 已提交
9

fxy060608's avatar
fxy060608 已提交
10 11 12 13 14
module.exports = (api, options) => { // 仅处理 app-plus 相关逻辑
  if (process.env.UNI_PLATFORM !== 'app-plus') {
    return
  }

fxy060608's avatar
fxy060608 已提交
15
  if (
fxy060608's avatar
fxy060608 已提交
16 17 18
    !process.env.UNI_USING_V3 &&
    !process.env.UNI_USING_NATIVE &&
    !process.env.UNI_USING_V3_NATIVE
fxy060608's avatar
fxy060608 已提交
19 20 21 22 23
  ) {
    if (!fs.existsSync(path.resolve(process.env.UNI_HBUILDERX_PLUGINS, 'weapp-tools/lib/index.js'))) {
      console.error('请使用 HBuilderX 编译运行至 app-plus 平台')
      process.exit(0)
    }
fxy060608's avatar
fxy060608 已提交
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
  }

  const plugins = []

  const output = {}
  const WebpackAppPlusPlugin = require('./packages/webpack-app-plus-plugin')

  plugins.push(new WebpackAppPlusPlugin())

  api.configureWebpack(webpackConfig => {
    return {
      output,
      plugins
    }
  })
}