情况:使用import.meta.globEager导入,得到的内容是空的,控制台也没有报错。解决:检查路径是否写正确,特别是写相对路径时,搞清楚是相对哪里。如果路径中并没有那个文件,引入内容就会是空的,控制台也不会报错。所以检查检查路径。...
:information: 从v0.6.x支持
Vite
2, v0.6.x支持
Vite
1。
npm i
vite
-plugin-components -D # yarn add
vite
-plugin-components -D
将其添加到
vite
.config.js
//
vite
.config.js
import
Vue from '@
vite
js/plugin-vue'
import
Vite
Components from '
vite
-plugin-components'
export default {
plugins : [
Vue ( ) ,
Vite
Components ( )
照常使用模板中的组件,但是不再需要
import
和component re
const files =
import
.
meta
.
glob
Eager
('./module/*.js')
注意,路径需为以 ./ 开头)或绝对路径(以 / 开头,相对于项目根目录解析
babel-plugin-bundled-
import
-
meta
Babel插件可重写
import
.
meta
.url以供捆绑使用。
安装babel-plugin-bundled-
import
-
meta
此模块需要node.js 10或更高版本以及@babel/core 。
npm i babel-plugin-bundled-
import
-
meta
将babel-plugin-bundled-
import
-
meta
到babel设置中的plugins 。
" plugins " : [
[ " babel-plugin-bundled-
import
-
meta
" , {
" mappings " : {
" node_modules " : " /assets "
" bundleDir " : " html "
接口、路由文件、store模块的自动化
引入
从require.context转为
import
.
meta
.
glob
Eager
,启动
vite
,浏览器
报错
import
_
meta
.
glob
Eager
is not a function
浏览器中定位错误发现,编译后的代码,将
import
_
meta
自动声明了
解决方案:
import
.
meta
vite
批量文件,由于无法使用require.context,所以使用的
import
.
meta
.
glob
Eager
或者
import
.
meta
.
glob
// 批量
引入
const modulesFiles =
import
.
meta
.
glob
Eager
("./modules/*.ts")
const modules = []
for (const key in modulesFiles) {
modules.push(...(modulesFiles[key].default))
const mo