node Vite 读取文件夹中所有文件
const path = require(‘path’)const files = require.context(’@/components/home’, false, /.vue$/)const modules = {}files.keys().forEach(key => {undefinedconst name = path.basename(key, ‘.vue’) //返回文件名
·
const files = require.context('./a',false,/\.js/)
const modules = {}
files.keys().forEach(key=>{
const filename = key.replace(/(\.\/|\.(js|ts))/g, "");
modules[filename] = files(key).default || files(key);
})
console.log(modules,"modules");
const modules = {}
const files = import.meta.globEager('./modules/*.js')
for (const key in files) {
const filename = key.replace(/(\.\/modules\/|\.(js|ts))/g, "");
modules[filename] = files[key].default || files[key]
}
console.log(modules)
更多推荐
已为社区贡献4条内容
所有评论(0)