2
我想知道是否有方法在React Native中記錄當前文件名或目錄。類似於NodeJS如何使用__filename
和__dirname
。在React Native中記錄當前目錄/文件名
我想知道是否有方法在React Native中記錄當前文件名或目錄。類似於NodeJS如何使用__filename
和__dirname
。在React Native中記錄當前目錄/文件名
不,這是不可能的,因爲所有源代碼都捆綁在一起成爲一個大文件,然後提供一個源映射,以便您可以在原始結構中進行調試。
你可以看到,在你的代碼某處調用此代碼片段:
console.log(new Error().stack);
在常規的JavaScript,你會得到的文件和行號,整個痕跡,但在反應母語你的財產以後,如:
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)"
它顯示你真實的文件已經消失。
如果我通過chrome運行react-native與遠程調試。我確實在每個console.log的最右側獲得了文件和行號。有沒有一種方法可以在我的代碼中訪問這些信息?即使只是在調試的時候。 – Dan