Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

动态导入字典在 vite 中失效 #1

Open
FreezeNow opened this issue Apr 14, 2023 · 1 comment
Open

动态导入字典在 vite 中失效 #1

FreezeNow opened this issue Apr 14, 2023 · 1 comment

Comments

@FreezeNow
Copy link

使用 vite 时,import() 不能使用绝对路径拼接,只能使用相对路径或者绝对路径字符串,希望修改导入相关代码,移除 '@/'+,并提示用户应该使用 '../'。该功能在 webpack 中可以正常使用。下面是例子:

import('@/dict.json') // 正常
import('../../dict.json') // 正常
var url = '../dict.json'
import(url) // 正常

var url = '@/dict.json' 
import(url) // 报错
var url = 'dict.json'
import(`@/${url}`) // 报错
import('@/' + url) // 报错
var url = 'dict.json'
import('../../' + url) // 报错,但不是无法引用,而是 MIME 不正确

// 该案例使用了 js 而不是 json
var url = 'dict.js'
import('../../' + url) // 正常
// dict.js
import baseDict from "./baseDict.json";
export default baseDict

参考资料:https://stackoverflow.com/questions/72845337/dynamic-import-of-component-does-not-work-with-component-path-from-variable

@FreezeNow
Copy link
Author

另外,这个组件在 vite + vue3 项目下基本无法运行,不知道是不是可以在 vue-cli + vue 3 下运行?如果只能在 vue-cli + vue 3下运行的话,能否在介绍中标注出来?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant