Babel file is copied without being transformed
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.
Babel Outputting Exact Copy of Angular2 File
Unfortunately babel 6 still has some issues, for example failing silently when a plugin is not found.
Install the following plugins:
babel-plugin-syntax-decorators
babel-plugin-transform-decorators
Include transform-decorators
plugin too in the options:
"plugins": [
"syntax-decorators",
"transform-decorators"
]
Most likely you will need a module transformer as well
But all of this is superfluous if your code is eventually TypeScript.
Babel has no effect on my Javascript
This caught me out too. The new version of Babel requires you to install a preset, probably the ES2015 one, and explicitly specify it in the CLI command.
Depending on where Babel is installed (globally/locally) that's where you need to install the preset:
npm install babel-preset-es2015
Then you can run Babel. This, for example, transforms all the files in one folder to another using the preset.
babel [srcFolder] --out-dir [outFolder] --presets es2015
Related Topics
How to Check If a Checkbox Is Checked
How to Listen to a "Style Change" Event
Working with Select Using Angularjs's Ng-Options
How to Download a File with Angular2 or Greater
JavaScript Regex Multiline Text Between Two Tags
Adding Click Event Listener to Elements with the Same Class
I Know That Callback Function Runs Asynchronously, But Why
Object.Watch() for All Browsers
Using JavaScript's Atob to Decode Base64 Doesn't Properly Decode Utf-8 Strings
Get the Closest Number Out of an Array
Babel File Is Copied Without Being Transformed
How to Prevent Enter Keypress to Submit a Web Form
How to Loop Through an Array Containing Objects and Access Their Properties
Concrete JavaScript Regular Expression for Accented Characters (Diacritics)
Advantages of Createelement Over Innerhtml
Variable as the Property Name in a JavaScript Object Literal
Function with Foreach Returns Undefined Even with Return Statement