scriptTag-custom.htm 914 B

12345678910111213141516171819202122232425262728293031
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8" />
  5. <title>babel-standalone example - Script tag</title>
  6. </head>
  7. <body>
  8. Using Babel <strong id="version"></strong>:
  9. <pre id="output">Loading...</pre>
  10. <script src="../babel.js"></script>
  11. <script type="text/javascript">
  12. // just disable the auto transformation
  13. Babel.disableScriptTags();
  14. var script = document.createElement('script');
  15. script.type = 'text/babel';
  16. script.text = "const doStuff = () => {" +
  17. " const name = 'world';" +
  18. " document.getElementById('output').innerHTML = `Hello ${name}`;" +
  19. " document.getElementById('version').innerHTML = Babel.version;" +
  20. "};" +
  21. "doStuff();";
  22. document.querySelector('head').appendChild(script)
  23. // transform when you want to
  24. Babel.transformScriptTags()
  25. </script>
  26. </body>
  27. </html>