Raul Vallespin Raul Vallespin - 1 year ago 66
Node.js Question

Babel file is copied without being transformed

I have this code:

"use strict";

import browserSync from "browser-sync";
import httpProxy from "http-proxy";

let proxy = httpProxy.createProxyServer({});

and i have installed babel-core and babel-cli globally via npm. The point is when I try to compile with this on my terminal:

babel proxy.js --out-file proxified.js

The output file gets COPIED NOT COMPILED (i mean, it's the same as the source file).

What i'm missing here?

Answer Source

Babel is a transformation framework. Pre-6.x, it enabled certain transformations by default, but with the increased usage of Node 4.x and 5.x, which natively support many ES6 features, it has become much more important that things be configurable. By default, Babel 6.x does not perform any transformations. You need to tell it what transformations to run:

npm install babel-preset-es2015

and run

babel --presets es2015 proxy.js --out-file proxified.js

or create a .babelrc file containing

    "presets": [

and run it just like you were before.

es2015 in this case is a preset which basically says to compile all ES6 to ES5. If you are using Node 4/5, you may want to consider other presets.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download