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

Why Is My Babel File Replicated Without Transformation?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-11-17 17:57:01232browse

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"
    ]
}
  • 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" } }]
    ]
}

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!

Statement:
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