0

I am attempting to use babel to transform client side ES6 scripts to ES5, and write that to a file.

However my current setup just spits out the same code that it took in.

Code example below.

const babel = require('babel-core');

babel.transform(scripts, {}, (err, result) => {
  fs.writeFileSync(
    '/scripts/app.main.js',
    result.code, 'utf8'
  );
});
DaBler
  • 2,695
  • 2
  • 26
  • 46
Brian Douglas
  • 81
  • 1
  • 3

1 Answers1

0

Babel 6.x does not ship with any transformations enabled. You need to explicitly tell it what transformations to run. The simplest way to do this is by using a preset, such as the ES2015 Preset.

So you need to use ES6->ES5 preset for example:

npm install babel-preset-es2015

Check https://babeljs.io/docs/plugins/preset-es2015/

Valentyn Shybanov
  • 19,331
  • 7
  • 66
  • 59