Skip to content

Commit ea044da

Browse files
BingBlogwangbing11
authored andcommitted
template add vue.config.js
1 parent f0605e4 commit ea044da

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

generator/template/vue.config.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
module.exports = {
2+
devServer: {
3+
compress: true,
4+
port: 9000,
5+
host: "0.0.0.0",
6+
historyApiFallback: true,
7+
hot: true,
8+
inline: true,
9+
open: true,
10+
before: function(app) {
11+
const path = require("path");
12+
const glob = require("glob");
13+
const mockApiData = getMockApiData();
14+
Object.keys(mockApiData).forEach(item => {
15+
app.all(`/api${item}`, function(req, res) {
16+
setTimeout(() => {
17+
res.json(mockApiData[item]);
18+
}, 1000);
19+
});
20+
});
21+
22+
function getMockApiData() {
23+
let mockPaths = glob.sync("**/__mock__/**/*.json", {
24+
cwd: path.resolve(__dirname, "./src")
25+
});
26+
let mockApiData = {};
27+
mockPaths.forEach(mockPath => {
28+
console.log(mockPath);
29+
const fileIndex = /^__mock__(.+)\.json/.exec(mockPath)[1];
30+
const filepath = path.resolve(
31+
path.resolve(__dirname, "./src"),
32+
mockPath
33+
);
34+
mockApiData[fileIndex] = require(filepath);
35+
});
36+
return mockApiData;
37+
}
38+
}
39+
}
40+
};

0 commit comments

Comments
 (0)