From d3077c51fcd0638878ba3478987a954f7a1adbc1 Mon Sep 17 00:00:00 2001 From: Nicolas Gotchac Date: Sun, 11 Dec 2016 15:05:10 +0100 Subject: [PATCH] Target Babel to latest Chrome Versions in dev (#3806) * Use `babel-preset-env` to target Babel to latest Chrome Versions * Opt-In mechanism for Babel Preset Env --- js/package.json | 1 + js/webpack/shared.js | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/js/package.json b/js/package.json index a8b156dd2..120ebb094 100644 --- a/js/package.json +++ b/js/package.json @@ -59,6 +59,7 @@ "babel-plugin-transform-runtime": "6.15.0", "babel-plugin-webpack-alias": "2.1.2", "babel-polyfill": "6.20.0", + "babel-preset-env": "1.0.2", "babel-preset-es2015": "6.18.0", "babel-preset-es2016": "6.16.0", "babel-preset-es2017": "6.16.0", diff --git a/js/webpack/shared.js b/js/webpack/shared.js index 8b6807b2a..3c593fd87 100644 --- a/js/webpack/shared.js +++ b/js/webpack/shared.js @@ -36,6 +36,29 @@ function getBabelrc () { // [ "es2015", { "modules": false } ] babelrc.presets[es2015Index] = [ 'es2015', { modules: false } ]; babelrc['babelrc'] = false; + + const BABEL_PRESET_ENV = process.env.BABEL_PRESET_ENV; + const npmStart = process.env.npm_lifecycle_event === 'start'; + const npmStartApp = process.env.npm_lifecycle_event === 'start:app'; + + if (BABEL_PRESET_ENV && (npmStart || npmStartApp)) { + console.log('using babel-preset-env'); + + babelrc.presets = [ + // 'es2017', + 'stage-0', 'react', + [ + 'env', + { + targets: { browsers: ['last 2 Chrome versions'] }, + modules: false, + loose: true, + useBuiltIns: true + } + ] + ]; + } + return babelrc; }