Home > Web Front-end > JS Tutorial > Why is my Babel output just a copy of the source file?

Why is my Babel output just a copy of the source file?

Susan Sarandon
Release: 2024-11-13 06:35:02
Original
751 people have browsed it

Why is my Babel output just a copy of the source file?

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
Copy after login

Subsequently, run the following command to invoke Babel with the env preset:

babel --presets env proxy.js --out-file proxified.js
Copy after login

Alternatively, users can create a .babelrc file with the following content:

{
    "presets": [
        "env"
    ]
}
Copy after login

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" } }],
    ]
}
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template