我想知道是否有办法在React Native中记录当前文件名或目录.类似于NodeJS如何使用__filename和__dirname.
不,这是不可能的,因为所有源代码都捆绑在一起到一个大文件中,然后提供源映射,以便您可以在原始结构中对其进行调试。
您可以通过在代码中的某个位置调用此代码片段来看到这一点:
console.log(new Error().stack);
Run Code Online (Sandbox Code Playgroud)
在常规的 javascript 中,您将获得包含文件和行号的完整跟踪,但在 React-native 中,您将获得类似以下内容的内容:
Error
at Login (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=true&minify=false:83009:9)
at instantiate (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=true&minify=false:5712:18)
at new Login (eval at proxyClass (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=true&minify=false:5730:16), <anonymous>:4:17)
at ReactCompositeComponentWrapper._constructComponentWithoutOwner (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=true&minify=false:22051:19)
at ReactCompositeComponentWrapper._constructComponent (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=true&minify=false:22033:13)
at ReactCompositeComponentWrapper.mountComponent (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=true&minify=false:21952:15)
at Object.mountComponent (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=true&minify=false:20425:29)
at ReactCompositeComponentWrapper.performInitialMount (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=true&minify=false:22134:28)
at ReactCompositeComponentWrapper.mountComponent (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=true&minify=false:22015:13)
at Object.mountComponent (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=true&minify=false:20425:29)"
Run Code Online (Sandbox Code Playgroud)
这表明真正的文件已经消失了。
| 归档时间: |
|
| 查看次数: |
1231 次 |
| 最近记录: |