banner



How To Install Babel Node

Full Stack engineer #React, #React-native, #JS tech and GraphQL + Crypto/Solidity enthusiast.

How to setup babel for node (Like shooting fish in a barrel)

Published Jan 12, 2022 Last updated Jul ten, 2022

How to setup babel for node (Easy)

Ok, if you are looking to setup a projection by scratch and want to utilize all the absurd functions from babel and the es6 syntax by default your code volition not be able to understand that syntax, and then showtime we should apply boom-boom, babel acts like a "translator".

Original commodity hither

Stride 0

Setup your environment

First things first, yous should create your project binder and inside your folder
initialize npm

Make sure you take node, obviously,

              npm init                          

next and next and you are done

Annotation: Your test code, can be anything. this sample volition follow the structure src/index.js where index.js is your lawmaking.

Step 1
Install dev-dependencies

              babel-cli babel-register boom-boom-preset-es2015 babel-presets-phase-two                          

Notation: in guild to utilize async and wait nosotros demand 2 more additional modules
This is helpful if you are going to employ some packages like redux-sagas,

              babel-cadre babel-polyfill                          

Install it every bit a Dev dependencies

              npm install babel-cli babel-annals babel-preset-es2015 babel-preset-stage-2 boom-boom-core babel-polyfill --save-dev                          

Pace 2

Setup boom-boom

Make a file .babelrc

              affect .babelrc                          

and in there add the babel configuration

              {   "presets": ["es2015", "stage-ii"] }                          

Pace 3

Setup environments

Create a folder when we are going to store both production and development files and configuration

              mkdir bin                          

and now create both env and prod files

              touch env touch prod                          

And in prod we are going to import our files from boom-boom

              crave('boom-boom-register') require("babel-core/register"); require("babel-polyfill"); // If you use async and await // This u.s.a. where our principal application index path is crave('../src/alphabetize');                          

At this indicate yous should be able to run the code by typing

              node bin/dev                          

And your code should run fine.

Step iv

Make the scripts to run the code

Ok, now we are ready to automate this using the npm scripts,
and then we should create both two new scipts beginning and build in our parcel.json

              "scripts": {     "start": "node bin/dev",     "build": "mkdir dist && babel src -south -d dist",     "dev": "nodemon --exec npm run boom-boom-node -- ./index.js",     "lint": "eslint"   },                          

This will run the app using the previous node control.

              "get-go": "node bin/dev"                          

And this create a new folder chosen dist

              "build": "mkdir dist && babel src -s -d dist",                          

I try to make it equally easy as possible, if any questions fell complimentary to leave a comment.

Discover and read more posts from Juan P. Ortiz

Source: https://www.codementor.io/@misterpoloy/how-to-setup-babel-for-node-easy-r55wb7uy6

Posted by: livingstonkneince.blogspot.com

0 Response to "How To Install Babel Node"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel