Skip to content

Commit

Permalink
centralise babel config
Browse files Browse the repository at this point in the history
  • Loading branch information
goto-bus-stop committed Sep 14, 2017
1 parent 06aba55 commit 017aa24
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 23 deletions.
7 changes: 1 addition & 6 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
{
"presets": [
["es2015", { "loose": true }],
"react"
],
"plugins": [
"transform-class-properties",
["transform-react-remove-prop-types", { "mode": "wrap" }]
"./preset"
]
}
29 changes: 29 additions & 0 deletions preset.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
module.exports = (babel, options) => {
const rollup = options && options.rollup;
const tests = options && options.tests;

const modules = rollup ? false : 'commonjs';
const plugins = [
'transform-class-properties',
['transform-react-remove-prop-types', { mode: 'wrap' }],
];

if (rollup) {
plugins.push('external-helpers');
}
if (tests) {
plugins.push('syntax-async-functions');
plugins.push(['transform-regenerator', { async: true }]);
}

return {
presets: [
['es2015', {
loose: true,
modules,
}],
'react',
],
plugins,
};
};
19 changes: 6 additions & 13 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,7 @@
import fs from 'fs';
import path from 'path';
import babel from 'rollup-plugin-babel';

const meta = require('./package.json');

// build a babel config that works for the rollup babel plugin
function getBabelConfig() {
const babelrc = fs.readFileSync(path.join(__dirname, '.babelrc'), 'utf8');
const babelConfig = JSON.parse(babelrc);
babelConfig.presets[0] = ['es2015', { loose: true, modules: false }];
babelConfig.plugins.push('external-helpers');
babelConfig.babelrc = false;
return babelConfig;
}

export default {
input: './src/index.js',
output: [
Expand All @@ -24,6 +12,11 @@ export default {
external: Object.keys(meta.dependencies)
.concat(Object.keys(meta.peerDependencies)),
plugins: [
babel(getBabelConfig()),
babel({
babelrc: false,
presets: [
[require.resolve('./preset'), { rollup: true }],
],
}),
],
};
6 changes: 2 additions & 4 deletions test/.babelrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{
"extends": "../.babelrc",
"plugins": [
"syntax-async-functions",
["transform-regenerator", { "async": true }]
"presets": [
["../preset", { "tests": true }]
]
}

0 comments on commit 017aa24

Please sign in to comment.