Can I Transpile for ES6-ES5 without npm, VS, Node, etc. and just the JS code itself somehow?

放肆的年华 提交于 2019-12-03 16:27:44

Yes, You can use ES6 without nodeJs, Follow the below steps

  1. Import babel script

  2. use instead of

  3. Write your ES6 code inside

Cons: You need write all ES6 code in the same HTML page, for example, if index.html is an entry point for the application, then you need to include ES6 code in the index.html page using the script tag of type "text/babel". You can't import the external ES6 file, it will throw cross-origin error.

You can write ES6 in the browser with the babel-standalone

<div id="output"></div>
<!-- Load Babel -->
<script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
<!-- Your custom script here -->
<script type="text/babel">
  const getMessage = () => "Hello World";
  document.getElementById('output').innerHTML = getMessage();
</script>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!