In your Babel configuration, you may encounter an issue where the output file is an exact replica of the source file, indicating a lack of transformation. To rectify this, it's crucial to explicitly define the transformations you wish Babel to perform.
Since Babel 6.x, default transformations are no longer implemented, meaning you need to specify the desired changes you want the compiler to make. One way to achieve this is by installing babel-preset-env:
npm install babel-preset-env
Once installed, run the following command:
babel --presets env proxy.js --out-file proxified.js
Alternatively, you can create a .babelrc file in your project directory and include the following content:
{ "presets": [ "env" ] }
This method configures Babel to perform the necessary transformations based on your Node.js version or target environment. For instance, you can use the following configuration to compile to ES5 while supporting ES6 syntax in your Node.js environment:
{ "presets": [ ["env", { "targets": { "node": "true" } }], ] }
By implementing these adjustments, Babel will now correctly transform your JavaScript code, resolving the issue of file copying and ensuring the desired changes are applied.
The above is the detailed content of Why Is My Babel File Being Copied Instead of Transformed?. For more information, please follow other related articles on the PHP Chinese website!