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

2022-06-13 16:15:08 浏览数 (1)

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

0 人点赞