javascript - 使用 npm 在 React Native 中使用范围导入
问题描述
我正在尝试改变在 React Native 中导入模块的方式。这样做的标准方法是这样的:
import HomeScreen from "../../screens/Home"
我也可以通过以下方式播种:
import HomeScreen from "@screens/Home"
为此,我尝试在屏幕文件夹中创建一个 package.json 文件并为其命名
{
"name": "@screens"
}
但不工作。
更新:
我尝试使用 babel-plugin-module-resolver 并使用我的 .babelrc 和 .tsconfig 对其进行配置,但问题仍然存在
.babelrc
{
"plugins": [
[
"module-resolver",
{
"root": ["./src"],
"alias": {
"test": "./test",
"underscore": "lodash"
}
}
]
]
}
tsconfig.json
{
"compilerOptions": {
"allowJs": false,
"allowSyntheticDefaultImports": true,
"experimentalDecorators": true,
"jsx": "react-native",
"module": "es2015",
"moduleResolution": "node",
"outDir": "build",
"rootDir": "src",
"noImplicitAny": false,
"noImplicitReturns": true,
"noImplicitThis": true,
"noUnusedLocals": true,
"sourceMap": true,
"target": "es2015",
"lib": ["es2015", "es2017", "dom"],
"skipLibCheck": true,
"baseUrl": ".",
"paths": {
"*": ["src/*"],
"test/*": ["test/*"],
"underscore": ["lodash"]
}
},
"exclude": ["node_modules"],
"include": ["src"]
}
PS:我也在使用打字稿
解决方案
推荐阅读
- scala - 有没有办法消耗来自kafka主题的所有消息并在那之后停止轮询?
- php - Laravel Nova HasOne 关系在单个面板中查看和编辑 2 个模型
- android - 如何解决 Android Studio 中的 IDE 错误?
- reactjs - Firebase orderByChild 不返回数组
- python - 使用 Python 创建 3 个 csv 文件的单个输出文件
- swift - 在 Swift 4 中提取部分字符串的最不复杂的方法
- upgrade - 将 X-cart 4.1.8 迁移到 X-cart 5 业务
- matlab - 使用 USB 麦克风采集原始数据
- agens-graph - 如何清除 AGENS 命令行上的屏幕
- javascript - AOT 是如何工作的,传统上 Javascript 说编译的结果不能在各种系统之间移植