[英]How to use babel-plugin-module-resolver to set an alias for the root path and disable other root imports?
我想做這樣import Foo from '~/components/Foo'
https://github.com/tleunen/babel-plugin-module-resolver
如果我將.babelrc
設置為:
{
"plugins": [
["module-resolver", {
"root": "./",
"alias": {
"~/": "./"
}
}]
]
}
我也嘗試過(以及許多其他組合):
{
"plugins": [
["module-resolver", {
"root": ".",
"alias": {
"~": "."
}
}]
]
}
然后我可以在這樣的腳本中使用它:
import Foo from 'components/Foo'
import Foo from '~/components/Foo'
它將不起作用(我希望它會這樣做)~/
前面加上,所以沒有多種使用模式。{
"plugins": [
["module-resolver", {
"root": ["./",]
"alias": {
"~/": "./"
}
}]
]
}
試試看
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.