简体   繁体   中英

React.js use custom js function from cef

I'm creating a UI for my launcher application which uses the chromium embedded framework for the web rendering. Now I register some custom javascript functions like launcher.getUser which would return the user as a json object. Now react.js is unable to use this function(as npm run build fails) since it's undefined. So I tried to define it in a separate.js file like this:

export class launcher
{
    static async getGames()
    {
        return undefined;
    }
    static async getUser()
    {
        return undefined;
    }
}
export class CefSharp
{
    static async BindObjectAsync(object)
    {
        return undefined;
    }
}

But the problem is that npm run build compiles it into something unreadable and as such the class is no longer named CefSharp and because of that it's not possible to bind the object. I was told to try and include it in the index.html in public but that doesn't allow me to use the function from react. I want to have npm run build not optimize the below code so it is the exact same in the production build.

I solved the issue by renaming the classes to launcherHelper and then calling eval('launcher.getGames();');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM