node环境下怎样优化引入多文件(实现自动化)

const mocks = [];
function getJsonFiles(jsonPath) {
function findJsonFile(path) {
let files = fs.readdirSync(path);
files.forEach(function(item) {
let fPath = join(path, item);
let stat = fs.statSync(fPath);
if (stat.isDirectory() === true) {
findJsonFile(fPath);
}
if (stat.isFile() === true) {
// 如果需要对指定路径进行处理
let str = fPath.substring(0, 10);
let newStr = fPath.replace(str, ‘./data/’);
// 否则直接require
mocks.push(…require(newStr));
}
});
}
findJsonFile(jsonPath);
}
getJsonFiles(’./mock/data’);

 

更多内容请见原文,原文转载自:https://blog.csdn.net/weixin_44519496/article/details/119809476

posted @ 2022-06-02 20:35  忘川信使  阅读(90)  评论(0编辑  收藏  举报