Babel: Preventing Untransformed File Copying
When compiling code using Babel, users may encounter a scenario where the output file is merely a copy of the source file, indicating a lack of transformation. This issue arises due to missing configuration settings in Babel 6.x.
By default, Babel 6.x requires explicit instructions for transformations. To address this, it is necessary to install the babel-preset-env package:
npm install babel-preset-env
Subsequently, run the following command to invoke Babel with the env preset:
babel --presets env proxy.js --out-file proxified.js
Alternatively, users can create a .babelrc file with the following content:
{ "presets": [ "env" ] }
This file allows running Babel with the same command as before.
The env preset compiles all ES* features to ES5 compatibility. For specific Node version support, include:
{ "presets": [ ["env", { "targets": { "node": "true" } }], ] }
Similarly, browser targets can be included for browser support.
The above is the detailed content of Why is my Babel output just a copy of the source file?. For more information, please follow other related articles on the PHP Chinese website!