![](https://img-blog.csdnimg.cn/2019091813595558.png?x-oss-process=image/resize,m_fixed,h_224,w_224)
Webpack
无
Tong XU
欣赏简洁的代码是一种赏心悦目的事情。
展开
-
使用require.context动态导入某个目录下的所有文件
import Vue from 'vue' const files = require.context('./', true, /\.vue$/) const lib = { } //key是相对路径名 files.keys().forEach(key => { const name = files(key).default.name lib[name] =...原创 2019-12-05 16:35:34 · 2775 阅读 · 0 评论 -
使用require.context实现前端工程自动化
require.context是什么 一个webpack的api,通过执行require.context函数获取一个特定的上下文,主要用来实现自动化导入模块,在前端工程中,如果遇到从一个文件夹引入很多模块的情况,可以使用这个api,它会遍历文件夹中的指定文件,然后自动导入,使得不需要每次显式的调用import导入模块 什么时候需要用到require.context 如果有以下情况,可以考虑使...转载 2019-12-05 15:53:38 · 117 阅读 · 0 评论