-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathpage.config.js
39 lines (33 loc) · 1013 Bytes
/
page.config.js
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
39
const fs = require("fs");
const Config = require("./src/config/page.js");
let pageConfig = {};
function addPageConfig(path, dir) {
if (isPage(path + "/" + dir)) {
if (pageConfig.dir) {
throw new Error("有名字重复的页面:" + dir);
}
let template = "public/index.html";
if (fs.existsSync(path + "/" + dir + "/index.html")) {
template = path + "/" + dir + "/index.html";
}
pageConfig[dir] = {
entry: path + "/" + dir + "/main.js",
filename: dir + ".html",
path: dir,
title: Config[dir] ? Config[dir].title : "",
template: template
};
}
let fileOrDir = fs.readdirSync(path + "/" + dir);
fileOrDir.forEach(function(file) {
let newDir = path + "/" + dir;
if (fs.statSync(newDir + "/" + file).isDirectory()) {
addPageConfig(newDir, file);
}
});
}
function isPage(dir) {
return fs.existsSync(dir + "/main.js") && fs.existsSync(dir + "/App.vue");
}
addPageConfig("src", "pages");
module.exports = pageConfig;