简体   繁体   English

无法在浏览器中将转换后的jsx运行为js文件。 在浏览器中要求jsxtransformer

[英]Unable to run transformed jsx to js file in browser. Asking for in browser jsxtransformer

I am trying to use reactify for jsx transformation and I have done the transformation from jsx to regular js using reactify. 我正在尝试使用reactify进行jsx转换,并且已经使用reactify完成了从jsx到常规js的转换。 But when I try to run my transformed js file, it's somehow not showing the content. 但是,当我尝试运行转换后的js文件时,它不显示任何内容。 But when I import in browser jsxtransformer then it's showing the content. 但是,当我在浏览器中导入jsxtransformer时,它将显示内容。 I am not able to understand the error in my procedure. 我无法理解我的程序中的错误。 If someone knows about it, please help me. 如果有人知道,请帮助我。 Thank You.. 谢谢..

As the documentation states , in-browser transpiling has been removed from Babel, however Daniel15 has created a standalone build for use in "non-Node.js environments including browsers" here: 文档所述 ,浏览器内的转译已从Babel中删除,但是Daniel15在此处创建了一个独立的版本,可用于“非Node.js环境,包括浏览器”:

https://github.com/Daniel15/babel-standalone https://github.com/Daniel15/babel-standalone

All you need to do is add this reference to your page: <script src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.4.4/babel.min.js"></script> 您需要做的就是将此引用添加到您的页面: <script src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.4.4/babel.min.js"></script>

And then make sure you're using the type="text/babel" attribute in your references to other script files, for example: 然后确保您在对其他脚本文件的引用中使用type="text/babel"属性,例如:

<script type="text/babel" src="scripts/myReactComponent.jsx"></script>

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

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