美文网首页
vue3 vite读取文件内容

vue3 vite读取文件内容

作者: 魔仙堡杠把子灬 | 来源:发表于2021-08-16 15:57 被阅读0次

原本努力是为了将一位少女揽入怀中,可后来我却见证了一位少年堕落的过程。

我的github: 李大玄
我的私人博客: 李大玄
我的npm开源库: 李大玄
我的简书: 李大玄
我的CSDN: 李大玄
我的掘金: 李大玄
哔哩哔哩: 李大玄

const modulesFiles = import.meta.globEager('./routerConfig/*.js');
let modules = [];
for (const path in modulesFiles) {
  modules = [].concat(modules, modulesFiles[path].default);
}

webpack


let routerArr = [];

// 自动加载该目录下的所有文件
const files = require.context('./', true, /\.(js)$/);
// 根据文件名组织模块对象
files.keys().map(src => {
  const match = src.match(/\/(.+)\./);
  if (match && match.length >= 1) {
    const moduleValue = files(src);
    if (moduleValue.default) {
      routerArr = [].concat(routerArr, moduleValue.default);
    }
  }
});
export default routerArr;

相关文章

网友评论

      本文标题:vue3 vite读取文件内容

      本文链接:https://www.haomeiwen.com/subject/dyombltx.html