Thursday, May 23, 2024
 Popular · Latest · Hot · Upcoming
106
rated 0 times [  113] [ 7]  / answers: 1 / hits: 41372  / 9 Years ago, fri, october 30, 2015, 12:00:00

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 instead of compiled (I mean, it's the same as the source file).



What am I missing here?


More From » babeljs

 Answers
39

Babel is a transformation framework. Pre-6.x, it enabled certain transformations by default, but with the increased usage of Node versions 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-env


and run



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


or create a .babelrc file containing



{
presets: [
env
]
}


and run it just like you were before.



env in this case is a preset which basically says to compile all standard ES* behavior to ES5. If you are using Node versions that support some ES6, you may want to consider doing



{
presets: [
[env, { targets: { node: true } }],
]
}


to tell the preset to only process things that are not supported by your Node version. You can also include browser versions in your targets if you need browser support.


[#64554] Tuesday, October 27, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
savanar

Total Points: 237
Total Questions: 105
Total Answers: 99

Location: Wales
Member since Mon, May 17, 2021
3 Years ago
;