admin管理员组文章数量:1333190
I saw some projects using import '@someDir/something'
, which solves the relative import evil.
Then I found this blog post talking about this method. It basically tells you to create package.json
in directories and specify their alias names.
I implemented it in my react-native project, which is based on expo, and it works well.
Something like this:
{"name": "@someDir"}
inside src/someDir/package.json
.
And I can import '@someDir/something'
everywhere.
Why is this working? Where is the magic happening behind? Webpack or babel or react-native itself?
I saw an issue discussing about this feature but I don't know where is it implemented.
My .babelrc
:
{
"presets": ["babel-preset-expo"],
"env": {
"development": {
"plugins": ["transform-react-jsx-source"]
}
}
}
It digged into the babel dependecies but cannot find anything related.
I saw some projects using import '@someDir/something'
, which solves the relative import evil.
Then I found this blog post talking about this method. It basically tells you to create package.json
in directories and specify their alias names.
I implemented it in my react-native project, which is based on expo, and it works well.
Something like this:
{"name": "@someDir"}
inside src/someDir/package.json
.
And I can import '@someDir/something'
everywhere.
Why is this working? Where is the magic happening behind? Webpack or babel or react-native itself?
I saw an issue discussing about this feature but I don't know where is it implemented.
My .babelrc
:
{
"presets": ["babel-preset-expo"],
"env": {
"development": {
"plugins": ["transform-react-jsx-source"]
}
}
}
It digged into the babel dependecies but cannot find anything related.
Share Improve this question edited Mar 12, 2018 at 18:21 Nakamura asked Mar 12, 2018 at 18:15 NakamuraNakamura 1,0412 gold badges13 silver badges23 bronze badges1 Answer
Reset to default 5It seems to be part of metro, the javascript bundler for react native.
https://www.belighted./blog/react-and-react-native-directories-management
https://facebook.github.io/metro
本文标签: javascriptreact nativeabsolute import with alias name in packagejsonStack Overflow
版权声明:本文标题:javascript - react native - absolute import with alias name in package.json - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742278089a2445575.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论