page.config.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. const fs = require("fs");
  2. const Config = require("./src/config/page.js");
  3. let pageConfig = {};
  4. function addPageConfig(path, dir) {
  5. if (isPage(path + "/" + dir)) {
  6. if (pageConfig.hasOwnProperty(dir)) {
  7. throw new Error("有名字重复的页面:" + dir);
  8. }
  9. let template = "public/index.html";
  10. if (fs.existsSync(path + "/" + dir + "/index.html")) {
  11. template = path + "/" + dir + "/index.html";
  12. }
  13. pageConfig[dir] = {
  14. entry: path + "/" + dir + "/index.js",
  15. filename: dir + ".html",
  16. path: dir,
  17. title: Config.hasOwnProperty(dir) ? Config[dir].title : "",
  18. template: template
  19. };
  20. }
  21. let fileOrDir = fs.readdirSync(path + "/" + dir);
  22. fileOrDir.forEach(function(file) {
  23. let newDir = path + "/" + dir;
  24. if (fs.statSync(newDir + "/" + file).isDirectory()) {
  25. addPageConfig(newDir, file);
  26. }
  27. });
  28. }
  29. function isPage(dir) {
  30. return fs.existsSync(dir + "/index.js") && fs.existsSync(dir + "/Index.vue");
  31. }
  32. addPageConfig("src", "pages");
  33. module.exports = pageConfig;