简体   繁体   English

Babel将JSX转换为JS

[英]Babel to translate JSX to JS

In C#, I get as an input a JSX file and want to translate it to JS. 在C#中,我得到一个JSX文件作为输入,并希望将其转换为JS。 I want to use the babel library, and used this guide: https://babeljs.io/docs/setup/#installation 我想使用babel库,并使用此指南: https : //babeljs.io/docs/setup/#installation

However, I am getting an exception of type: 但是,我得到一个类型的异常:

An unhandled exception of type 'React.TinyIoC.TinyIoCResolutionException' occurred in React.Core.dll React.Core.dll中发生了类型为'React.TinyIoC.TinyIoCResolutionException'的未处理异常

Additional information: Unable to resolve type: React.IReactEnvironment 附加信息:无法解析类型:React.IReactEnvironment

for this line: ReactEnvironment.Current 对于这一行:ReactEnvironment.Current

I have tried to create a new ASP.NET project, and no exception was thrown and everything worked just fine. 我尝试创建一个新的ASP.NET项目,没有引发异常,并且一切正常。

My question is: How can I still use babel in non web project? 我的问题是:如何在非Web项目中仍然使用babel?

You need to run an extra initialization step for non Web applications. 您需要为非Web应用程序运行一个额外的初始化步骤。 This initialization step is automatically done in Web applications. 此初始化步骤在Web应用程序中自动完成。

If its a console application then use this function, 如果它是控制台应用程序,则使用此功能,

        private static void Initialize()
        {
            Initializer.Initialize(registration => registration.AsSingleton());
            var container = React.AssemblyRegistration.Container;
            // Register some components that are normally provided by the integration library
            // (eg. React.AspNet or React.Web.Mvc6)
            container.Register<ICache, NullCache>();
            container.Register<IFileSystem, SimpleFileSystem>();
        }

And call it in the main method. 并在main方法中调用它。

Take a look at the github console sample app for React.Net 看看React.Net的github控制台示例应用程序

Link for reference 参考链接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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