Home > Web Front-end > JS Tutorial > Why Is My Babel File Replicated Without Transformation?

Why Is My Babel File Replicated Without Transformation?

Mary-Kate Olsen
Release: 2024-11-17 17:57:01
Original
291 people have browsed it

Why Is My Babel File Replicated Without Transformation?

Babel File Replicated Without Transformation

Your code snippet employs browserSync and http-proxy to create a proxy server. However, running babel proxy.js --out-file proxified.js yields only a copy of the original file.

Babel, a transformation framework, has undergone a change in default behavior from pre-6.x versions. Previously, specific transformations were enabled by default, but current versions require explicit configuration.

To specify transformations, you need:

  • Install babel-preset-env with npm install babel-preset-env.
  • Run babel --presets env proxy.js --out-file proxified.js or create a .babelrc file with the following contents:
{
    "presets": [
        "env"
    ]
}
Copy after login
  • Then, run the command as before.

The "env" preset compiles standard ES* behavior to ES5. If your Node version supports ES6 features, consider using the following .babelrc to process only unsupported features:

{
    "presets": [
        ["env", { "targets": { "node": "true" } }]
    ]
}
Copy after login

You can further customize targets if required for browser support.

The above is the detailed content of Why Is My Babel File Replicated Without Transformation?. 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