From cf2910cf79a216206c5be289205bd2fe24b90416 Mon Sep 17 00:00:00 2001 From: Bogdan Chadkin Date: Tue, 11 Apr 2017 20:14:09 +0300 Subject: [PATCH] Reduce babel config (#349) * Reduce babel config * Transpile es to cjs per file --- .babelrc | 61 ++++++++++++++++++++++++---------------- package.json | 5 ++-- scripts/release.js | 6 ++-- scripts/rollup.config.js | 31 +------------------- 4 files changed, 44 insertions(+), 59 deletions(-) diff --git a/.babelrc b/.babelrc index 6c615265..c252b768 100644 --- a/.babelrc +++ b/.babelrc @@ -1,30 +1,41 @@ { "plugins": [ - "babel-plugin-transform-function-bind", - "babel-plugin-transform-class-constructor-call", - ["babel-plugin-transform-class-properties", { "loose": true }], - "babel-plugin-transform-export-extensions", - "babel-plugin-syntax-trailing-function-commas", - "babel-plugin-transform-object-rest-spread", - "babel-plugin-transform-async-to-generator", + "transform-function-bind", + "transform-class-constructor-call", + ["transform-class-properties", { "loose": true }], + "transform-export-extensions", + "syntax-trailing-function-commas", + "transform-object-rest-spread", + "transform-async-to-generator", - "babel-plugin-transform-react-jsx", - "babel-plugin-syntax-jsx", - "babel-plugin-transform-react-display-name", + "transform-react-jsx", + "syntax-jsx", + "transform-react-display-name", - ["babel-plugin-transform-es2015-template-literals", { "loose": true }], - "babel-plugin-transform-es2015-literals", - "babel-plugin-transform-es2015-function-name", - "babel-plugin-transform-es2015-arrow-functions", - "babel-plugin-transform-es2015-block-scoped-functions", - ["babel-plugin-transform-es2015-classes", { "loose": true }], - "babel-plugin-transform-es2015-shorthand-properties", - ["babel-plugin-transform-es2015-computed-properties", { "loose": true }], - ["babel-plugin-transform-es2015-spread", { "loose": true }], - "babel-plugin-transform-es2015-parameters", - ["babel-plugin-transform-es2015-destructuring", { "loose": true }], - "babel-plugin-transform-es2015-block-scoping", - ["babel-plugin-transform-es2015-modules-commonjs", { "loose": true }], - "babel-plugin-transform-regenerator" - ] + ["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-shorthand-properties", + ["transform-es2015-computed-properties", { "loose": true }], + ["transform-es2015-spread", { "loose": true }], + "transform-es2015-parameters", + ["transform-es2015-destructuring", { "loose": true }], + "transform-es2015-block-scoping", + "transform-regenerator" + ], + "env": { + "cjs": { + "plugins": [ + ["transform-es2015-modules-commonjs", { "loose": true }] + ] + }, + "rollup": { + "plugins": [ + "external-helpers" + ] + } + } } diff --git a/package.json b/package.json index a7067973..12a22a9c 100644 --- a/package.json +++ b/package.json @@ -9,8 +9,8 @@ "license": "MIT", "scripts": { "lint": "eslint scripts src", - "test": "ava --concurrency=5", - "test:watch": "npm run test -- --watch", + "test": "cross-env BABEL_ENV=cjs ava --concurrency=5", + "test:watch": "npm test -- --watch", "release": "babel-node scripts/release.js", "postinstall": "babel-node scripts/installNestedPackageDeps.js" }, @@ -53,6 +53,7 @@ "change-case": "^2.3.1", "codecov": "^1.0.1", "create-react-class": "^15.5.0", + "cross-env": "^4.0.0", "enzyme": "^2.2.0", "eslint": "^2.10.2", "eslint-config-airbnb": "9.0.1", diff --git a/scripts/release.js b/scripts/release.js index af3566fa..c1a630f6 100644 --- a/scripts/release.js +++ b/scripts/release.js @@ -88,7 +88,9 @@ const run = async () => { }).map(to => path.relative(sourceDir, to)) exec( - `cd ${sourceDir} && ${path.resolve(BIN)}/babel ${sourceFiles.join(' ')} ` + + `cd ${sourceDir} && ` + + 'cross-env BABEL_ENV=cjs ' + + `${path.resolve(BIN)}/babel ${sourceFiles.join(' ')} ` + `--out-dir ${path.resolve(outDir)}` ) @@ -121,7 +123,7 @@ const run = async () => { log(`Building ${packageName}...`) const runRollup = build => - 'rollup --config scripts/rollup.config.js ' + + 'cross-env BABEL_ENV=rollup rollup --config scripts/rollup.config.js ' + `--environment BUILD:${build},PACKAGE_NAME:${packageName}` if (exec([ runRollup('es'), diff --git a/scripts/rollup.config.js b/scripts/rollup.config.js index 0cd37ffb..58aee954 100644 --- a/scripts/rollup.config.js +++ b/scripts/rollup.config.js @@ -24,36 +24,7 @@ const config = { moduleName: libraryName, plugins: [ babel({ - exclude: 'node_modules/**', - babelrc: false, - plugins: [ - 'babel-plugin-transform-function-bind', - 'babel-plugin-transform-class-constructor-call', - ['babel-plugin-transform-class-properties', { loose: true }], - 'babel-plugin-transform-export-extensions', - 'babel-plugin-syntax-trailing-function-commas', - 'babel-plugin-transform-object-rest-spread', - 'babel-plugin-transform-async-to-generator', - - 'babel-plugin-transform-react-jsx', - 'babel-plugin-syntax-jsx', - 'babel-plugin-transform-react-display-name', - - ['babel-plugin-transform-es2015-template-literals', { loose: true }], - 'babel-plugin-transform-es2015-literals', - 'babel-plugin-transform-es2015-function-name', - 'babel-plugin-transform-es2015-arrow-functions', - 'babel-plugin-transform-es2015-block-scoped-functions', - ['babel-plugin-transform-es2015-classes', { loose: true }], - 'babel-plugin-transform-es2015-shorthand-properties', - ['babel-plugin-transform-es2015-computed-properties', { loose: true }], - ['babel-plugin-transform-es2015-spread', { loose: true }], - 'babel-plugin-transform-es2015-parameters', - ['babel-plugin-transform-es2015-destructuring', { loose: true }], - 'babel-plugin-transform-es2015-block-scoping', - 'babel-plugin-transform-regenerator', - 'babel-plugin-external-helpers' - ] + exclude: '**/node_modules/**' }) ] }