page.js 768 B

123456789101112131415161718192021222324252627
  1. const path = require('path')
  2. const fs = require('fs')
  3. const fromFile = path.join(__filename, '../../pages.json')
  4. const toFile = path.join(__filename, '../../router/index.js')
  5. const buffPrefix = Buffer.from('export default ')
  6. const fileData = fs.readFileSync(fromFile)
  7. // 转成可读的js, 正则删除注释, 不然JSON.parse会报错
  8. const fileObj = JSON.parse(fileData.toString().replace(/\/\/.*/g, ''))
  9. // 遍历,只取路径和标题,其他的不要,已减小文件体积
  10. const routes = fileObj.pages.map(e => {
  11. return {
  12. title: e.style ? e.style.navigationBarTitleText : '未知',
  13. path: e.path,
  14. }
  15. })
  16. fs.writeFileSync(toFile, buffPrefix + Buffer.from(JSON.stringify(routes)))
  17. module.exports = {
  18. configureWebpack: {
  19. plugins: []
  20. }
  21. }