vite global batch acquisition of file content globEager

For example, in the front-end project of vite+vue3, each module will accompany you to route separately, and then through a general router js file, the file content of all file modules will be centrally called

const files = import.meta.globEager('@/view/*/router.js');

let route = [];

for (const f in files) {
    
    
  const o = files[f].default;
  o.path = o.path || `/${
      
      f.split('/')[2]}`;
  route = [].concat(route, o);
}

console.log(route)

Guess you like

Origin blog.csdn.net/weixin_34403976/article/details/128675088