diff --git a/webpack/webpack-utils/find-file.js b/webpack/webpack-utils/find-file.js new file mode 100644 index 00000000..c6c79365 --- /dev/null +++ b/webpack/webpack-utils/find-file.js @@ -0,0 +1,20 @@ +const fs = require('fs'); +const Path = require('path'); + +function findFile(path, target) { + for (const name of fs.readdirSync(path)) { + const filePath = Path.join(path, name); + const stat = fs.lstatSync(filePath); + + if (stat.isDirectory() && name !== 'node_modules') { + const result = findFile(filePath, target); + if (result) { + return result; + } + } else if (name === target) { + return filePath; + } + } +} + +module.exports = { findFile };