define-pages.js 870 字节
Newer Older
fxy060608's avatar
fxy060608 已提交
1 2 3 4 5 6 7 8 9 10 11 12
function generatePageCode (pages, pageOptions) {
  return pages.map(pagePath => {
    if (pageOptions[pagePath].nvue) {
      return ''
    }
    return `__definePage('${pagePath}',function(){return Vue.extend(require('${pagePath}.vue').default)})`
  }).join('\n')
}

module.exports = function definePages (appJson) {
  return {
    name: 'define-pages.js',
13 14 15 16 17 18 19 20 21 22 23 24
    content: `
if (!Promise.prototype.finally) {
  Promise.prototype.finally = function(callback) {
    const promise = this.constructor
    return this.then(
      value => promise.resolve(callback()).then(() => value),
      reason => promise.resolve(callback()).then(() => {
        throw reason
      })
    )
  }
}
fxy060608's avatar
fxy060608 已提交
25
if(uni.restoreGlobal){
fxy060608's avatar
fxy060608 已提交
26
  uni.restoreGlobal(weex,plus,setTimeout,clearTimeout,setInterval,clearInterval)
fxy060608's avatar
fxy060608 已提交
27
}
fxy060608's avatar
fxy060608 已提交
28 29 30 31
${generatePageCode(appJson.pages, appJson.page)}
`
  }
}