js 查找当前文件夹的文件是否存在

 

const imgFiles = (require as any).context("./", false, /(\.png)|(\.jpg)$/)
const imgUrls: any = {}

imgFiles.keys().forEach((key: string) => {
  const id = key.slice(2, -4)
  imgUrls[id] = require(`./${key.slice(2)}`)
})

export default imgUrls

posted on 2024-06-10 19:10  完美前端  阅读(73)  评论(0编辑  收藏  举报

导航