ember-cli-babel
ember-cli-babel copied to clipboard
preset is not working on Babel 6
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']
},
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...
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.
Yes, totally agreed.
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);
}
};
Closing as v6 is not supported anymore.