javascripttypescriptstaticconsole.logweb-inspector

Access items inside Webpack bundle in browser console


I am using Typescript with Webpack (debug build using source maps). I can access Static class files in the sources tab normally. However, the class name itself is undefined at the global scope.

class SomeStaticClass {
  public static doSomething() {
     console.log("I just did something!");
  }
}

I would like to access / call

SomeStaticClass.doSomething() 

from console in the browser (say Google Chrome Inspector Tools). How can I achieve this?


Solution

  • I managed a workaround like the following. In the main exports.tsx (assuming this is the top level export):

    import { StaticClassToBeExposed } from '...SomeFile';
    
    if(type of window !== undefined) {
       window.StaticClassToBeExposed = StaticClassToBeExposed;
    }