karlakmkj

Transpilation from ES6 to ES5

Dec 21st, 2020 (edited)
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. 1. Initialize your project using npm init and create a directory called src -- creates a package.json file in the root directory
  3. To install babel dependencies
  4. 2. In terminal window, type this to install one of the two required Babel packages : npm install babel-cli  
  5. 3. Then type this to install the second of two required Babel packages: npm install babel-preset-env
  6.  
  7. 4. Type touch .babelrc to create file inside your project and add the following code inside it:
  8. {
  9.   "presets": ["env"]
  10. }
  11. 5. Add the following script to your scripts object in package.json:
  12. "build": "babel src -d lib"
  13.  
  14. 6. Lastly, type this to see the newly created lib directory : npm run build -- to transpile your code from your src to lib directories.
  15. */
  16.  
  17. //Original ES6 code
  18. var pasta = "Spaghetti"; // ES5 syntax
  19.  
  20. const meat = "Pancetta"; // ES6 syntax
  21.  
  22. let sauce = "Eggs and cheese"; // ES6 syntax
  23.  
  24. // Template literals, like the one below, were introduced in ES6
  25. const carbonara = `You can make carbonara with ${pasta}, ${meat}, and a sauce made with ${sauce}.`;
  26.  
  27. =======================================================================================================================
  28. //Transpiled ES5 code
  29. "use strict";
  30.  
  31. var pasta = "Spaghetti"; // ES5 syntax
  32.  
  33. var meat = "Pancetta";
  34.  
  35. var sauce = "Eggs and cheese";
  36.  
  37. // Template literals, like the one below, were introduced in ES6
  38. var carbonara = "You can make carbonara with " + pasta + ", " + meat + ", and a sauce made with " + sauce + ".";
Add Comment
Please, Sign In to add comment