0

Looking at this question, it is possible to retrieve the path of the current source file by accessing the last <script> element in the document during initialization.

This works fine, however I am working with react and transpiling my source files with babel. So instead of getting the original source file name, the above solution would get me something like 'bundle.js' which means very little to me.

To give some context, I am trying to enable/disable logging at the switch of a bool by overriding console's log and dir functions. If this functionality is described in say debug.js, then the source for my logs (as specified in the console) will be that file. So I'd like to log an extra piece of information to say which file the call to console.log occurred.

sookie
  • 2,437
  • 3
  • 29
  • 48
  • why does it matter? There is no way the "compiled" source would know where it was compiled from, it's also pretty meaningless. – Liam Dec 06 '17 at 14:48
  • 1
    @Liam : That doesn't seem like a good justification to downvote a question. There are plenty of reasons why one might want to know where a log is happening in large projects, especially if you're not the only developer. – sookie Dec 06 '17 at 14:50
  • 1
    I suspect the answer will involve "source maps" but I don't know enough about them and how Babel interacts with them to give a full answer. – Quentin Dec 06 '17 at 14:51
  • There is a presumption that I downvoted there? – Liam Dec 06 '17 at 14:59

0 Answers0