How to transpile inline/embedded javascript using

2020-07-11 09:58发布

问题:

I use "babel" command to transpile ES6 script to ES5.

Ex: babel testES6.js --out-file testES5.js

It works fine. My question is how to transpile inline javascript. For Ex: test.html

<html>
   <head>
      <script type="text/javascript">
          //ES6 scripts
      </script>
   </head>
</html>

回答1:

According the babel docs, it supports scripts typed text/ecmascript-6 or text/babel. Add the browser build into your page and set proper type for your scripts.



回答2:

You can use this code and enjoy :)

<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.21.1/babel.min.js"></script>
<script type="text/babel">

</script>


标签: babeljs