webpack与vite批量导入异同

webpack

let modules = require.context('./modules', false, /\.ts$/),

modules.keys().forEach((key) => {
    let item = files(key).default
    console.log(item)
})

vite

let modules = import.meta.globEager('./modules/*.ts')

Object.keys(modules).forEach((key) => {
    let item = files[key].default
    console.log(item)
})
posted @ 2023-04-07 11:13  杜柯枫  阅读(19)  评论(0编辑  收藏  举报