ember-cli-babel icon indicating copy to clipboard operation
ember-cli-babel copied to clipboard

preset is not working on Babel 6

Open Cryrivers opened this issue 8 years ago • 4 comments
trafficstars

I tried to add preset in my Babel options. However, it doesn't work.

 babel: {
      presets: ['es2015', 'es2016', 'es2017', 'stage-2'],
      plugins: ['transform-decorators-legacy']
  },

Cryrivers avatar May 15 '17 04:05 Cryrivers

At this time the only options we support are passed directly to babel-preset-env (which does not have anpreset option).

It is possible for us to add the ability to configure additional presets like you have shown, but we need to think through the ramifications and whatnot...

rwjblue avatar May 15 '17 12:05 rwjblue

Stumbled upon this as well.

Presets would be quite useful for when you want to transpile stage-2 features down to latest, so that env can take it from there.

buschtoens avatar Jul 05 '17 11:07 buschtoens

Yes, totally agreed.

rwjblue avatar Jul 05 '17 12:07 rwjblue

Cool, maybe I can get around to submit a PR. In the meantime I just manually include all plugins, that I actually use. In order to DRY it up, I've moved that to an extra util. If I recall correctly, you were the one who suggested that on Slack. Thanks!

Should anyone have the same issue, here's what I do. :slightly_smiling_face:

// lib/utils/setup-babel.js
module.exports = function(app) {
  app.options = app.options || {};
  const babel = app.options.babel = app.options.babel || {};
  babel.plugins = babel.plugins || [];

  for (const plugin of plugins) {
    if (!babel.plugins.includes(plugin)) {
      babel.plugins.push(plugin);
    }
  }
};

const plugins = module.exports.plugins = [
  'transform-class-properties',
  'transform-decorators-legacy',
  'transform-object-rest-spread'
];
// ember-cli-build.js
const EmberApp = require('ember-cli/lib/broccoli/ember-app');

module.exports = function(defaults) {
  const env = EmberApp.env();

  const app = new EmberApp(defaults, {
    babel: {
      plugins: require('./lib/utils/setup-babel').plugins
    }
  });

  return app;
};
// lib/in-repo-addon/index.js
const setupBabel = require('../utils/setup-babel');

module.exports = {
  name: 'in-repo-addon',

  init() {
    this._super.init && this._super.init.apply(this, arguments);
    setupBabel(this);
  }
};

buschtoens avatar Jul 05 '17 13:07 buschtoens

Closing as v6 is not supported anymore.

bertdeblock avatar Jan 28 '23 10:01 bertdeblock