Skip to content

Instantly share code, notes, and snippets.

@leonid-bauxy
Created August 1, 2016 20:05
Show Gist options
  • Save leonid-bauxy/48d132157906708cc8666f8ec563a535 to your computer and use it in GitHub Desktop.
Save leonid-bauxy/48d132157906708cc8666f8ec563a535 to your computer and use it in GitHub Desktop.
./helpers/getBabelConfig.js
import _ from 'lodash';
import getEnvHelpers from './getEnvHelpers';
/**
* Returns babel config, for use with `babel-loader`
*
* @returns {Object}
*/
export default function getBabelConfig() {
const {
isProd,
ifProd,
ifNotProd,
ifTest,
} = getEnvHelpers();
return {
babelrc: false,
comments: !isProd,
compact: false,
ast: false,
cacheDirectory: true,
presets: _.compact([
ifProd('react-optimize'),
]),
plugins: _.compact([
'transform-decorators-legacy',
'transform-class-properties',
'transform-proto-to-assign',
'transform-object-set-prototype-of-to-assign',
['transform-builtin-extend', {
'globals': ['Error'],
'approximate': true,
}],
'transform-object-rest-spread',
['transform-es2015-template-literals', { 'loose': true }],
'transform-es2015-literals',
'transform-es2015-function-name',
'transform-es2015-arrow-functions',
'transform-es2015-block-scoped-functions',
['transform-es2015-classes', { 'loose': true }],
'transform-es2015-object-super',
'transform-es2015-shorthand-properties',
'transform-es2015-duplicate-keys',
['transform-es2015-computed-properties', { 'loose': true }],
['transform-es2015-for-of', { 'loose': true }],
'transform-es2015-sticky-regex',
'transform-es2015-unicode-regex',
'check-es2015-constants',
['transform-es2015-spread', { 'loose': true }],
'transform-es2015-parameters',
['transform-es2015-destructuring', { 'loose': true }],
'transform-es2015-block-scoping',
'transform-es2015-typeof-symbol',
'transform-react-jsx',
'transform-react-display-name',
ifProd('lodash'),
ifNotProd('transform-react-jsx-self'),
ifTest(['transform-es2015-modules-commonjs', { 'loose': true }]),
]),
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment