build.qa.js 2.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 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
const fs = require('fs')
const del = require('del')
const path = require('path')
const copy = require('copy')
const rollup = require('rollup')

const genConfig = require('./rollup.config.qa')

const filename = 'vue.' + (process.env.NODE_ENV === 'production' ? 'prod' : 'dev') + '.js'

async function build () {
  const bridgeBundle = await rollup.rollup(genConfig('bridge'))
  const {
    output: bridgeOutput
  } = await bridgeBundle.generate({
    format: 'iife'
  })
  const bridgeCode = bridgeOutput[0].code
  const appBundle = await rollup.rollup(genConfig('app'))
  const {
    output: appOutput
  } = await appBundle.generate({
    format: 'iife',
    banner: `
dsl.onInitApp(function({
    inst,
    context,
    instRequireModule
}) {
    if(!context.quickapp.dock.makeEvaluateBuildScript){
      context.quickapp.dock.makeEvaluateBuildScript = args => args
    }
    const $app_require$ = instRequireModule;
`,
    footer: `
});`
  })
  const appCode = appOutput[0].code
fxy060608's avatar
fxy060608 已提交
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
  const pageBundle = await rollup.rollup(genConfig('page'))
  const {
    output: pageOutput
  } = await pageBundle.generate({
    format: 'iife',
    banner: `
  dsl.onInitPage(function({
    $app_require$,
    Vue
  }) {
  `,
    footer: `
  });`
  })
  const pageCode = pageOutput[0].code
fxy060608's avatar
fxy060608 已提交
54
  const vueCode = fs.readFileSync(path.resolve(__dirname, '../packages/uni-quickapp-native/assets/' + filename))
fxy060608's avatar
fxy060608 已提交
55 56

  fs.writeFileSync(
fxy060608's avatar
fxy060608 已提交
57
    path.resolve(__dirname, '../packages/uni-quickapp-native/dist/' + filename),
fxy060608's avatar
fxy060608 已提交
58
    vueCode + bridgeCode + appCode + pageCode, {
fxy060608's avatar
fxy060608 已提交
59 60 61 62
      encoding: 'utf8'
    }
  )

fxy060608's avatar
fxy060608 已提交
63
  if (process.env.NODE_ENV === 'production') { // 命令会执行dev,prod两次,仅prod时执行copy
fxy060608's avatar
fxy060608 已提交
64 65
    const componentsSrc = path.resolve(__dirname, '../src/platforms/quickapp-native/view/components/**/*')
    const componentsDest = path.resolve(__dirname, '../packages/uni-quickapp-native/components')
fxy060608's avatar
fxy060608 已提交
66 67 68 69 70 71 72 73 74 75 76 77

    del.sync([componentsDest])

    copy(componentsSrc, componentsDest, function (err, file) {
      if (err) {
        throw err
      }
    })
  }
}

build()