Do I need Babel to transpile ES6 to ES5 nowadays? - node.js

I'm trying to upgrade an angularJS project and I'm stucked on one question, but let me summerize the project:
We use AngularJS, gulp and node 8.
we currently cannot use the ES6 features, like arrow functions, const/let and so on.
I achieved that by installing babels plugin. But babel transpiles the code, and the company staff doesn't want that, cause it can make it difficult to debug on production(I know we can use sourcemaps, it will be suggested).
We just want to write ES6 code and read(on the browser) the same code as we do now (but with es5)
I upgraded node to 10 and I thought that by upgrading node, the app would accept the new ES6 features. But still crashes when using es6 syntax.
Can someone tell me why? If the browsers accepts, why gulp doesnt?

Related

Why webpack and babel are dependent on Node.js to run?

I was learning babel and webpack and then it turns out I need to install node.js to run them both and I asked myself WHY? Then according to my research, we need node.js for webpack and babel since both of them were written in JS and to run that JS code which transpiles( for babel) and bundles up the code(for webpack). Also, another reason is that since both babel and webpack handles our JS code outside of the browser, this is the reason to use Node.js. Are these reasons true?
According to the Node.js website -
Node.jsĀ® is a JavaScript runtime built on Chrome's V8 JavaScript engine.
Webpack and babel (along with many other tools you might use for frontend development) are written in javascript and since they are command line tools, they need a way to run outside of the browser (directly on your machine).
They could have used some other language to write the tools but since they chose to write them in javascript, Node.js is the only feasible options right now.
In case you are interested, the original creator of nodejs
Ryan Dahl has built another secure runtime environment for Javascript/Typescript called Deno
Yes, at the moment the node.js project is non-portable by full open source disclosure nor extension to port node.js commonjs without a just in time transpiler with a service worker on a server.
Definitions: FHC = "from half court"
Babel and webpack
(1) transpile/move (write&read, not ln -s sym...bolic link) & (2) compost/pile onto a JIT target,
like v8 or other browser-javascript-interpreters. v8 on a service worker can compile on the edge just in time for interpretation in a browser v8 environment but still on the cloudflare edge server.
Declare (FHC) Allegedly, rust provides webassembly modules with the lipid [llvm-]wrappings
that nucleic acid exocytosis needs to be a full-blown virus, err I mean
Initiation Routine needs to be a targetable JIT extension!
A compiler/transpiler still requires it's target-scope receivable. Declare (FHC) Emit is to execute as compile is to interpret, even AST.

Using Node.js with Gulp, Babel, Webpack?

Some Node.js projects use things like Babel, Gulp, Webpack. Other Node.js projects don't use such things. Do I have to use them in my Node.js projects and why? Perhaps you know different cases when I should take one of these decision?
No, you do not need.
Webpack is a bundler, it is intended to help packing up multiple files into one single file. Throughout this process you can transpile the code to apply modifications on it, eg: convert from es6 to es5 (if needed).
To transpile your code from es6 to es5, you are going to need babel, where you can do a lot of stuff with that.
Gulp is a task runner/manager, not used that often since most of people use webpack nowadays. But still useful for a bunch of stuff.
If you are going to develop pure node.js projects, you don't have to worry about this. For web you should be aware of all of these tools.
I've found Babel, Gulp, Webpack can be used in Node.js projects with cases:
you need to minimize production code.
you'd like to use all ES6+ features (like 'export' and 'import', decorators).
you want to use JavaScript extensions like TypeScript.
If for some reason your project contains .js files are intended to run in different environments (Node.js, casperjs, browsers), you would like to use ES6+ inside all .js files.

Publish/Target npm package for different node versions

I have written a node module using ES7 features. I've also created a build script which transpiles to ES5.
Is there a way to publish the module, so that a node 8/9 user uses the original code and older node versions use the transpiled code?
The reason why I want this, is because I expect a better performance on the none transpiled code.
As far as I understand, the perfomance differnce between the transpiled code and ES7 code is negligible.
So it suffices to just publish the transpiled code.

Typescript Async/Await Need solution for ES5?

I just found out that async/await in TypeScript isn't supported unless you use ES6, which we cannot use. TypeScript 2.0 beta is coming out "still" without this feature.
What solution can I use, can I do an "npm install promises" and use that, or does that require ES6 too? I do not want to roll my own solution here. Does anyone know of a npm package that can do async/await syntax without ES6? We are doing pure node.js side coding.

why it possible to use destructuring assignment in React Native?

In the example of react native tutorial, I find syntax which is defined in ECMAScript 2015 (ES6) standard called Destructuring assignment. But as I know, iojs and nodejs do not support this syntax. How can I use it in React Native?
You are right nodejs and iojs do not support ES6 syntax. But react native:
As of version 0.5.0, React Native ships with the Babel JavaScript compiler.
Read more here
That means that there is another transpiler (Babel) at work in the React packager. It converts from ECMAScript 2015 (ES6) to ES5. This allows you to use the ES6 features like: destructuring, computed property keys, classes, arrow functions, block-scoped variables and more.
If you want to use those features in the React (not Native) app, you will need to include Babel in your project.
Edit:
There is no another transpiler.
React and React Native have both switched their respective build systems to make use of Babel. This replaced JSTransform, the source transformation tool that we wrote at Facebook.
More in Deprecating JSTransform and react-tools

Resources