config-parser.js 571 字节
Newer Older
fxy060608's avatar
init v3  
fxy060608 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
function generatePageCode (pages) {
  return pages.map(pagePath => {
    return `__registerPage('${pagePath}',function(){
      const cacheKey = '${pagePath}-VueComponent'
      if(!this[cacheKey]){
        this[cacheKey] = Vue.extend(require('${pagePath}.vue').default)
      }
      return this[cacheKey]
    })`
  }).join('\n')
}

module.exports = function parseConfig (appJson) {
  return {
    name: 'app-config.js',
    content: `
import Vue from 'vue'
__registerConfig(${JSON.stringify(appJson)},Vue)
${generatePageCode(appJson.pages)}
`
  }
}