From 58b5d6d22fc117a1c886d6b7138c4d2edb9c1ab3 Mon Sep 17 00:00:00 2001
From: Norbert de Langen <ndelangen@me.com>
Date: Wed, 16 Aug 2017 21:58:17 +0200
Subject: [PATCH 1/3] WIP

---
 addons/storyshots/package.json                |  2 +-
 app/react-native/package.json                 |  3 +-
 app/react-native/src/server/config/babel.js   | 25 ++++----------
 .../src/server/config/babel.prod.js           | 27 ++++-----------
 app/react/package.json                        |  3 +-
 app/react/src/server/babel_config.test.js     |  6 ++--
 app/react/src/server/config/babel.js          | 32 ++++++++++++------
 app/react/src/server/config/babel.prod.js     | 31 ++++++++++-------
 app/vue/src/server/babel_config.test.js       |  6 ++--
 app/vue/src/server/config/babel.js            | 33 +++++++++++--------
 app/vue/src/server/config/babel.prod.js       | 30 +++++++++++------
 lib/cli/generators/METEOR/index.js            | 11 +++----
 lib/ui/example/package.json                   |  2 +-
 lib/ui/example/webpack.config.js              |  2 +-
 14 files changed, 109 insertions(+), 104 deletions(-)

diff --git a/addons/storyshots/package.json b/addons/storyshots/package.json
index 51ef59e9dbf0..5cad32661a77 100644
--- a/addons/storyshots/package.json
+++ b/addons/storyshots/package.json
@@ -25,7 +25,7 @@
     "@storybook/react": "^3.2.4",
     "babel-cli": "^6.24.1",
     "babel-plugin-transform-runtime": "^6.23.0",
-    "babel-preset-es2015": "^6.24.1",
+    "babel-preset-env": "^1.6.0",
     "babel-preset-react": "^6.24.1",
     "react": "^15.6.1",
     "react-dom": "^15.6.1"
diff --git a/app/react-native/package.json b/app/react-native/package.json
index bc1a4fb3e67b..12bd4ed841bc 100644
--- a/app/react-native/package.json
+++ b/app/react-native/package.json
@@ -40,8 +40,7 @@
     "babel-plugin-transform-regenerator": "^6.24.1",
     "babel-plugin-transform-runtime": "^6.23.0",
     "babel-polyfill": "^6.23.0",
-    "babel-preset-es2015": "^6.24.1",
-    "babel-preset-es2016": "^6.24.1",
+    "babel-preset-env": "^1.6.0",
     "babel-preset-react": "^6.24.1",
     "babel-preset-stage-0": "^6.24.1",
     "babel-runtime": "^6.23.0",
diff --git a/app/react-native/src/server/config/babel.js b/app/react-native/src/server/config/babel.js
index 6499e3fe3580..840ab348bd1f 100644
--- a/app/react-native/src/server/config/babel.js
+++ b/app/react-native/src/server/config/babel.js
@@ -1,33 +1,20 @@
-/**
- * Copyright (c) 2015-present, Facebook, Inc.
- * All rights reserved.
- *
- * This source code is licensed under the BSD-style license found in the
- * LICENSE file in the root directory of this source tree. An additional grant
- * of patent rights can be found in the PATENTS file in the same directory.
- */
-
 module.exports = {
   // Don't try to find .babelrc because we want to force this configuration.
   babelrc: false,
   presets: [
-    // let, const, destructuring, classes, modules
-    require.resolve('babel-preset-es2015'),
-    // exponentiation
-    require.resolve('babel-preset-es2016'),
-    // JSX, Flow
+    [
+      require.resolve('babel-preset-env'),
+      {
+        modules: false,
+      },
+    ],
     require.resolve('babel-preset-react'),
   ],
   plugins: [
-    // function x(a, b, c,) { }
     require.resolve('babel-plugin-syntax-trailing-function-commas'),
-    // await fetch()
     require.resolve('babel-plugin-syntax-async-functions'),
-    // class { handleClick = () => { } }
     require.resolve('babel-plugin-transform-class-properties'),
-    // { ...todo, completed: true }
     require.resolve('babel-plugin-transform-object-rest-spread'),
-    // function* () { yield 42; yield 43; }
     require.resolve('babel-plugin-transform-regenerator'),
     // Polyfills the runtime needed for async/await and generators
     [
diff --git a/app/react-native/src/server/config/babel.prod.js b/app/react-native/src/server/config/babel.prod.js
index 12359442f545..840ab348bd1f 100644
--- a/app/react-native/src/server/config/babel.prod.js
+++ b/app/react-native/src/server/config/babel.prod.js
@@ -1,33 +1,20 @@
-/**
- * Copyright (c) 2015-present, Facebook, Inc.
- * All rights reserved.
- *
- * This source code is licensed under the BSD-style license found in the
- * LICENSE file in the root directory of this source tree. An additional grant
- * of patent rights can be found in the PATENTS file in the same directory.
- */
-
 module.exports = {
   // Don't try to find .babelrc because we want to force this configuration.
   babelrc: false,
   presets: [
-    // let, const, destructuring, classes, modules
-    require.resolve('babel-preset-es2015'),
-    // exponentiation
-    require.resolve('babel-preset-es2016'),
-    // JSX, Flow
+    [
+      require.resolve('babel-preset-env'),
+      {
+        modules: false,
+      },
+    ],
     require.resolve('babel-preset-react'),
   ],
   plugins: [
-    // function x(a, b, c,) { }
     require.resolve('babel-plugin-syntax-trailing-function-commas'),
-    // await fetch()
     require.resolve('babel-plugin-syntax-async-functions'),
-    // class { handleClick = () => { } }
     require.resolve('babel-plugin-transform-class-properties'),
-    // { ...todo, completed: true }
     require.resolve('babel-plugin-transform-object-rest-spread'),
-    // function* () { yield 42; yield 43; }
     require.resolve('babel-plugin-transform-regenerator'),
     // Polyfills the runtime needed for async/await and generators
     [
@@ -38,7 +25,5 @@ module.exports = {
         regenerator: true,
       },
     ],
-    // Optimization: hoist JSX that never changes out of render()
-    require.resolve('babel-plugin-transform-react-constant-elements'),
   ],
 };
diff --git a/app/react/package.json b/app/react/package.json
index 1b3867692849..3e8a0ed188ce 100644
--- a/app/react/package.json
+++ b/app/react/package.json
@@ -32,8 +32,7 @@
     "babel-core": "^6.25.0",
     "babel-loader": "^7.0.0",
     "babel-plugin-react-docgen": "^1.6.0",
-    "babel-preset-es2015": "^6.24.1",
-    "babel-preset-es2016": "^6.24.1",
+    "babel-preset-env": "^1.6.0",
     "babel-preset-react": "^6.24.1",
     "babel-preset-react-app": "^3.0.0",
     "babel-preset-stage-0": "^6.24.1",
diff --git a/app/react/src/server/babel_config.test.js b/app/react/src/server/babel_config.test.js
index b993216203e5..7fc9fac65c6c 100644
--- a/app/react/src/server/babel_config.test.js
+++ b/app/react/src/server/babel_config.test.js
@@ -12,7 +12,7 @@ describe('babel_config', () => {
     mock({
       '.babelrc': `{
         "presets": [
-          "es2015",
+          "env",
           "foo-preset"
         ],
         "plugins": [
@@ -41,7 +41,7 @@ describe('babel_config', () => {
     mock({
       '.babelrc': `{
         "presets": [
-          "es2015",
+          "env",
           "foo-preset"
         ],
         "plugins": "bar-plugin"
@@ -68,7 +68,7 @@ describe('babel_config', () => {
     mock({
       '.babelrc': `{
         "presets": [
-          "es2015",
+          "env",
           "foo-preset"
         ]
       }`,
diff --git a/app/react/src/server/config/babel.js b/app/react/src/server/config/babel.js
index 231735a40cc8..0754c278511c 100644
--- a/app/react/src/server/config/babel.js
+++ b/app/react/src/server/config/babel.js
@@ -1,19 +1,31 @@
-/**
- * Copyright (c) 2015-present, Facebook, Inc.
- * All rights reserved.
- *
- * This source code is licensed under the BSD-style license found in the
- * LICENSE file in the root directory of this source tree. An additional grant
- * of patent rights can be found in the PATENTS file in the same directory.
- */
+const findCacheDir = require('find-cache-dir');
 
 module.exports = {
   // Don't try to find .babelrc because we want to force this configuration.
   babelrc: false,
+  cacheDirectory: findCacheDir({ name: 'react-storybook' }),
   presets: [
-    require.resolve('babel-preset-es2015'),
-    require.resolve('babel-preset-es2016'),
+    [
+      require.resolve('babel-preset-env'),
+      {
+        targets: {
+          browsers: ['last 2 versions', 'safari >= 7'],
+        },
+        modules: false,
+      },
+    ],
     require.resolve('babel-preset-stage-0'),
     require.resolve('babel-preset-react'),
   ],
+  plugins: [
+    require.resolve('babel-plugin-transform-regenerator'),
+    [
+      require.resolve('babel-plugin-transform-runtime'),
+      {
+        helpers: true,
+        polyfill: true,
+        regenerator: true,
+      },
+    ],
+  ],
 };
diff --git a/app/react/src/server/config/babel.prod.js b/app/react/src/server/config/babel.prod.js
index 231735a40cc8..31c88ebfcf7a 100644
--- a/app/react/src/server/config/babel.prod.js
+++ b/app/react/src/server/config/babel.prod.js
@@ -1,19 +1,28 @@
-/**
- * Copyright (c) 2015-present, Facebook, Inc.
- * All rights reserved.
- *
- * This source code is licensed under the BSD-style license found in the
- * LICENSE file in the root directory of this source tree. An additional grant
- * of patent rights can be found in the PATENTS file in the same directory.
- */
-
 module.exports = {
   // Don't try to find .babelrc because we want to force this configuration.
   babelrc: false,
   presets: [
-    require.resolve('babel-preset-es2015'),
-    require.resolve('babel-preset-es2016'),
+    [
+      require.resolve('babel-preset-env'),
+      {
+        targets: {
+          browsers: ['last 2 versions', 'safari >= 7'],
+        },
+        modules: false,
+      },
+    ],
     require.resolve('babel-preset-stage-0'),
     require.resolve('babel-preset-react'),
   ],
+  plugins: [
+    require.resolve('babel-plugin-transform-regenerator'),
+    [
+      require.resolve('babel-plugin-transform-runtime'),
+      {
+        helpers: true,
+        polyfill: true,
+        regenerator: true,
+      },
+    ],
+  ],
 };
diff --git a/app/vue/src/server/babel_config.test.js b/app/vue/src/server/babel_config.test.js
index b993216203e5..7fc9fac65c6c 100644
--- a/app/vue/src/server/babel_config.test.js
+++ b/app/vue/src/server/babel_config.test.js
@@ -12,7 +12,7 @@ describe('babel_config', () => {
     mock({
       '.babelrc': `{
         "presets": [
-          "es2015",
+          "env",
           "foo-preset"
         ],
         "plugins": [
@@ -41,7 +41,7 @@ describe('babel_config', () => {
     mock({
       '.babelrc': `{
         "presets": [
-          "es2015",
+          "env",
           "foo-preset"
         ],
         "plugins": "bar-plugin"
@@ -68,7 +68,7 @@ describe('babel_config', () => {
     mock({
       '.babelrc': `{
         "presets": [
-          "es2015",
+          "env",
           "foo-preset"
         ]
       }`,
diff --git a/app/vue/src/server/config/babel.js b/app/vue/src/server/config/babel.js
index 6715e3f302d8..0754c278511c 100644
--- a/app/vue/src/server/config/babel.js
+++ b/app/vue/src/server/config/babel.js
@@ -1,24 +1,31 @@
-/**
- * Copyright (c) 2015-present, Facebook, Inc.
- * All rights reserved.
- *
- * This source code is licensed under the BSD-style license found in the
- * LICENSE file in the root directory of this source tree. An additional grant
- * of patent rights can be found in the PATENTS file in the same directory.
- */
-
 const findCacheDir = require('find-cache-dir');
 
 module.exports = {
   // Don't try to find .babelrc because we want to force this configuration.
   babelrc: false,
-  // This is a feature of `babel-loader` for webpack (not Babel itself).
-  // It enables a cache directory for faster-rebuilds
-  // `find-cache-dir` will create the cache directory under the node_modules directory.
   cacheDirectory: findCacheDir({ name: 'react-storybook' }),
   presets: [
-    require.resolve('babel-preset-env'),
+    [
+      require.resolve('babel-preset-env'),
+      {
+        targets: {
+          browsers: ['last 2 versions', 'safari >= 7'],
+        },
+        modules: false,
+      },
+    ],
     require.resolve('babel-preset-stage-0'),
     require.resolve('babel-preset-react'),
   ],
+  plugins: [
+    require.resolve('babel-plugin-transform-regenerator'),
+    [
+      require.resolve('babel-plugin-transform-runtime'),
+      {
+        helpers: true,
+        polyfill: true,
+        regenerator: true,
+      },
+    ],
+  ],
 };
diff --git a/app/vue/src/server/config/babel.prod.js b/app/vue/src/server/config/babel.prod.js
index d772440e5eb1..31c88ebfcf7a 100644
--- a/app/vue/src/server/config/babel.prod.js
+++ b/app/vue/src/server/config/babel.prod.js
@@ -1,18 +1,28 @@
-/**
- * Copyright (c) 2015-present, Facebook, Inc.
- * All rights reserved.
- *
- * This source code is licensed under the BSD-style license found in the
- * LICENSE file in the root directory of this source tree. An additional grant
- * of patent rights can be found in the PATENTS file in the same directory.
- */
-
 module.exports = {
   // Don't try to find .babelrc because we want to force this configuration.
   babelrc: false,
   presets: [
-    require.resolve('babel-preset-env'),
+    [
+      require.resolve('babel-preset-env'),
+      {
+        targets: {
+          browsers: ['last 2 versions', 'safari >= 7'],
+        },
+        modules: false,
+      },
+    ],
     require.resolve('babel-preset-stage-0'),
     require.resolve('babel-preset-react'),
   ],
+  plugins: [
+    require.resolve('babel-plugin-transform-regenerator'),
+    [
+      require.resolve('babel-plugin-transform-runtime'),
+      {
+        helpers: true,
+        polyfill: true,
+        regenerator: true,
+      },
+    ],
+  ],
 };
diff --git a/lib/cli/generators/METEOR/index.js b/lib/cli/generators/METEOR/index.js
index 1cbc30e0b187..55e19589b60e 100644
--- a/lib/cli/generators/METEOR/index.js
+++ b/lib/cli/generators/METEOR/index.js
@@ -9,8 +9,7 @@ module.exports = Promise.all([
   latestVersion('@storybook/react'),
   latestVersion('react'),
   latestVersion('react-dom'),
-  latestVersion('babel-preset-es2015'),
-  latestVersion('babel-preset-es2016'),
+  latestVersion('babel-preset-env'),
   latestVersion('babel-preset-react'),
   latestVersion('babel-preset-stage-1'),
   latestVersion('babel-root-slash-import'),
@@ -20,8 +19,7 @@ module.exports = Promise.all([
       storybookVersion,
       reactVersion,
       reactDomVersion,
-      presetEs2015Version,
-      presetEs2016Version,
+      presetEnvVersion,
       presetReactVersion,
       presetStage1Version,
       rootSlashImportVersion,
@@ -47,12 +45,11 @@ module.exports = Promise.all([
       }
     } else {
       babelrc = {
-        presets: ['es2015', 'es2016', 'react', 'stage-1'],
+        presets: ['env', 'react', 'stage-1'],
         plugins: ['babel-root-slash-import'],
       };
 
-      packageJson.devDependencies['babel-preset-es2015'] = `^${presetEs2015Version}`;
-      packageJson.devDependencies['babel-preset-es2016'] = `^${presetEs2016Version}`;
+      packageJson.devDependencies['babel-preset-env'] = `^${presetEnvVersion}`;
       packageJson.devDependencies['babel-preset-react'] = `^${presetReactVersion}`;
       packageJson.devDependencies['babel-preset-stage-1'] = `^${presetStage1Version}`;
       packageJson.devDependencies['babel-root-slash-import'] = `^${rootSlashImportVersion}`;
diff --git a/lib/ui/example/package.json b/lib/ui/example/package.json
index 9163920f76ce..9e4380c99b64 100644
--- a/lib/ui/example/package.json
+++ b/lib/ui/example/package.json
@@ -9,7 +9,7 @@
     "babel-core": "^6.25.0",
     "babel-eslint": "^7.2.2",
     "babel-loader": "^7.0.0",
-    "babel-preset-es2015": "^6.24.1",
+    "babel-preset-env": "^1.6.0",
     "babel-preset-react": "^6.24.1",
     "babel-preset-stage-0": "^6.24.1",
     "eslint": "^3.19.0",
diff --git a/lib/ui/example/webpack.config.js b/lib/ui/example/webpack.config.js
index 83f56d360bb1..526fe795ac52 100644
--- a/lib/ui/example/webpack.config.js
+++ b/lib/ui/example/webpack.config.js
@@ -18,7 +18,7 @@ module.exports = {
       {
         test: /\.js$/,
         loader: require.resolve('babel-loader'),
-        query: { presets: ['react', 'es2015', 'stage-0'] },
+        query: { presets: ['react', 'env', 'stage-0'] },
         include: [path.join(__dirname, 'client'), path.resolve(__dirname, '../src')],
       },
     ],

From a9b55dc7146529458dd8e804eb2ff715fa41da71 Mon Sep 17 00:00:00 2001
From: Norbert de Langen <ndelangen@me.com>
Date: Wed, 16 Aug 2017 22:32:52 +0200
Subject: [PATCH 2/3] ADD minify

---
 app/react-native/package.json                      | 1 +
 app/react-native/src/server/config/babel.prod.js   | 1 +
 app/react/package.json                             | 1 +
 app/react/src/server/config/babel.prod.js          | 1 +
 app/react/src/server/config/webpack.config.prod.js | 2 +-
 app/vue/package.json                               | 1 +
 app/vue/src/server/config/babel.prod.js            | 1 +
 app/vue/src/server/config/webpack.config.prod.js   | 2 +-
 8 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/app/react-native/package.json b/app/react-native/package.json
index 12bd4ed841bc..b8f67e660c4d 100644
--- a/app/react-native/package.json
+++ b/app/react-native/package.json
@@ -41,6 +41,7 @@
     "babel-plugin-transform-runtime": "^6.23.0",
     "babel-polyfill": "^6.23.0",
     "babel-preset-env": "^1.6.0",
+    "babel-preset-minify": "^0.2.0",    
     "babel-preset-react": "^6.24.1",
     "babel-preset-stage-0": "^6.24.1",
     "babel-runtime": "^6.23.0",
diff --git a/app/react-native/src/server/config/babel.prod.js b/app/react-native/src/server/config/babel.prod.js
index 840ab348bd1f..45f88f5607f4 100644
--- a/app/react-native/src/server/config/babel.prod.js
+++ b/app/react-native/src/server/config/babel.prod.js
@@ -9,6 +9,7 @@ module.exports = {
       },
     ],
     require.resolve('babel-preset-react'),
+    require.resolve('babel-preset-minify'),
   ],
   plugins: [
     require.resolve('babel-plugin-syntax-trailing-function-commas'),
diff --git a/app/react/package.json b/app/react/package.json
index 3e8a0ed188ce..a0a5b54a0480 100644
--- a/app/react/package.json
+++ b/app/react/package.json
@@ -33,6 +33,7 @@
     "babel-loader": "^7.0.0",
     "babel-plugin-react-docgen": "^1.6.0",
     "babel-preset-env": "^1.6.0",
+    "babel-preset-minify": "^0.2.0",
     "babel-preset-react": "^6.24.1",
     "babel-preset-react-app": "^3.0.0",
     "babel-preset-stage-0": "^6.24.1",
diff --git a/app/react/src/server/config/babel.prod.js b/app/react/src/server/config/babel.prod.js
index 31c88ebfcf7a..59a87fe49bc3 100644
--- a/app/react/src/server/config/babel.prod.js
+++ b/app/react/src/server/config/babel.prod.js
@@ -13,6 +13,7 @@ module.exports = {
     ],
     require.resolve('babel-preset-stage-0'),
     require.resolve('babel-preset-react'),
+    require.resolve('babel-preset-minify'),
   ],
   plugins: [
     require.resolve('babel-plugin-transform-regenerator'),
diff --git a/app/react/src/server/config/webpack.config.prod.js b/app/react/src/server/config/webpack.config.prod.js
index 989b1adca7ad..da40e8ccc017 100644
--- a/app/react/src/server/config/webpack.config.prod.js
+++ b/app/react/src/server/config/webpack.config.prod.js
@@ -29,7 +29,7 @@ export default function() {
           screw_ie8: true,
           warnings: false,
         },
-        mangle: false,
+        mangle: true,
         output: {
           comments: false,
           screw_ie8: true,
diff --git a/app/vue/package.json b/app/vue/package.json
index da51c84666fa..d834420bf35f 100644
--- a/app/vue/package.json
+++ b/app/vue/package.json
@@ -33,6 +33,7 @@
     "babel-loader": "^7.0.0",
     "babel-plugin-react-docgen": "^1.6.0",
     "babel-preset-env": "^1.6.0",
+    "babel-preset-minify": "^0.2.0",
     "babel-preset-react": "^6.24.1",
     "babel-preset-react-app": "^3.0.0",
     "babel-preset-stage-0": "^6.24.1",
diff --git a/app/vue/src/server/config/babel.prod.js b/app/vue/src/server/config/babel.prod.js
index 31c88ebfcf7a..59a87fe49bc3 100644
--- a/app/vue/src/server/config/babel.prod.js
+++ b/app/vue/src/server/config/babel.prod.js
@@ -13,6 +13,7 @@ module.exports = {
     ],
     require.resolve('babel-preset-stage-0'),
     require.resolve('babel-preset-react'),
+    require.resolve('babel-preset-minify'),
   ],
   plugins: [
     require.resolve('babel-plugin-transform-regenerator'),
diff --git a/app/vue/src/server/config/webpack.config.prod.js b/app/vue/src/server/config/webpack.config.prod.js
index 3df8cd742875..1067704d0184 100644
--- a/app/vue/src/server/config/webpack.config.prod.js
+++ b/app/vue/src/server/config/webpack.config.prod.js
@@ -29,7 +29,7 @@ export default function() {
           screw_ie8: true,
           warnings: false,
         },
-        mangle: false,
+        mangle: true,
         output: {
           comments: false,
           screw_ie8: true,

From 39140d874255dea87996a58e15c45df10f03e8c4 Mon Sep 17 00:00:00 2001
From: Norbert de Langen <ndelangen@me.com>
Date: Thu, 17 Aug 2017 18:04:20 +0200
Subject: [PATCH 3/3] REVERT mangle setting

---
 app/react/src/server/config/webpack.config.prod.js | 2 +-
 app/vue/src/server/config/webpack.config.prod.js   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/app/react/src/server/config/webpack.config.prod.js b/app/react/src/server/config/webpack.config.prod.js
index da40e8ccc017..989b1adca7ad 100644
--- a/app/react/src/server/config/webpack.config.prod.js
+++ b/app/react/src/server/config/webpack.config.prod.js
@@ -29,7 +29,7 @@ export default function() {
           screw_ie8: true,
           warnings: false,
         },
-        mangle: true,
+        mangle: false,
         output: {
           comments: false,
           screw_ie8: true,
diff --git a/app/vue/src/server/config/webpack.config.prod.js b/app/vue/src/server/config/webpack.config.prod.js
index 1067704d0184..3df8cd742875 100644
--- a/app/vue/src/server/config/webpack.config.prod.js
+++ b/app/vue/src/server/config/webpack.config.prod.js
@@ -29,7 +29,7 @@ export default function() {
           screw_ie8: true,
           warnings: false,
         },
-        mangle: true,
+        mangle: false,
         output: {
           comments: false,
           screw_ie8: true,