diff --git a/babelRegisterOnly.js b/babelRegisterOnly.js index 349ba638..bf328610 100644 --- a/babelRegisterOnly.js +++ b/babelRegisterOnly.js @@ -8,9 +8,22 @@ */ 'use strict'; +require('babel-polyfill'); + +var fs = require('fs'); +var path = require('path'); + var _only = []; +function readBabelRC() { + var rcpath = path.join(__dirname, 'react-packager', '.babelrc'); + var source = fs.readFileSync(rcpath).toString(); + return JSON.parse(source); +} + module.exports = function(onlyList) { _only = _only.concat(onlyList); - require('babel-core/register')({only: _only}); + var config = readBabelRC(); + config.only = _only; + require('babel-core/register')(config); }; diff --git a/react-packager/.babelrc b/react-packager/.babelrc index 602c9fe6..3882b9be 100644 --- a/react-packager/.babelrc +++ b/react-packager/.babelrc @@ -1,27 +1,29 @@ -// Keep in sync with packager/transformer.js { "retainLines": true, "compact": true, "comments": false, - "whitelist": [ - "es6.arrowFunctions", - "es6.blockScoping", - "es6.classes", - "es6.constants", - "es6.destructuring", - "es6.modules", - "es6.parameters", - "es6.properties.computed", - "es6.properties.shorthand", - "es6.spread", - "es6.templateLiterals", - "es7.asyncFunctions", - "es7.trailingFunctionCommas", - "es7.objectRestSpread", - "flow", - "react", - "react.displayName", - "regenerator" + "plugins": [ + "syntax-async-functions", + "syntax-class-properties", + "syntax-trailing-function-commas", + "transform-es2015-arrow-functions", + "transform-es2015-block-scoping", + "transform-es2015-classes", + "transform-es2015-computed-properties", + "transform-es2015-constants", + "transform-es2015-destructuring", + ["transform-es2015-modules-commonjs", {"strict": false, "allowTopLevelThis": true}], + "transform-es2015-parameters", + "transform-es2015-shorthand-properties", + "transform-es2015-spread", + "transform-es2015-template-literals", + "transform-class-properties", + "transform-flow-strip-types", + "transform-object-assign", + "transform-object-rest-spread", + "transform-react-display-name", + "transform-react-jsx", + "transform-regenerator" ], "sourceMaps": false } diff --git a/transformer.js b/transformer.js index b07e7b5e..e7368cc6 100644 --- a/transformer.js +++ b/transformer.js @@ -18,10 +18,7 @@ function transform(src, filename, options) { const plugins = []; if (options.inlineRequires) { - plugins.push({ - position: 'after', - transformer: inlineRequires, - }); + plugins.push([inlineRequires]); } const result = babel.transform(src, { @@ -29,31 +26,33 @@ function transform(src, filename, options) { compact: true, comments: false, filename, - whitelist: [ + plugins: plugins.concat([ // Keep in sync with packager/react-packager/.babelrc - 'es6.arrowFunctions', - 'es6.blockScoping', - 'es6.classes', - 'es6.constants', - 'es6.destructuring', - 'es6.modules', - 'es6.parameters', - 'es6.properties.computed', - 'es6.properties.shorthand', - 'es6.spread', - 'es6.templateLiterals', - 'es7.asyncFunctions', - 'es7.trailingFunctionCommas', - 'es7.objectRestSpread', - 'flow', - 'react', - 'react.displayName', - 'regenerator', - ], - plugins, + 'syntax-async-functions', + 'syntax-class-properties', + 'syntax-jsx', + 'syntax-trailing-function-commas', + 'transform-class-properties', + 'transform-es2015-arrow-functions', + 'transform-es2015-block-scoping', + 'transform-es2015-classes', + 'transform-es2015-computed-properties', + 'transform-es2015-constants', + 'transform-es2015-destructuring', + ['transform-es2015-modules-commonjs', {strict: false, allowTopLevelThis: true}], + 'transform-es2015-parameters', + 'transform-es2015-shorthand-properties', + 'transform-es2015-spread', + 'transform-es2015-template-literals', + 'transform-flow-strip-types', + 'transform-object-assign', + 'transform-object-rest-spread', + 'transform-react-display-name', + 'transform-react-jsx', + 'transform-regenerator', + ]), sourceFileName: filename, sourceMaps: false, - extra: options || {}, }); return {