diff --git a/experimental/babel-preset-env/README.md b/experimental/babel-preset-env/README.md
index 08c606cc7b..6e3e7e97f3 100644
--- a/experimental/babel-preset-env/README.md
+++ b/experimental/babel-preset-env/README.md
@@ -120,16 +120,6 @@ A query to select browsers (ex: last 2 versions, > 5%) using [browserslist](http
Note, browsers' results are overridden by explicit items from `targets`.
-### `targets.uglify`
-
-`number | true`
-
-UglifyJS does not currently support any ES6 syntax, so if you are using Uglify to minify your code, targeting later browsers may cause Uglify to throw syntax errors.
-
-To prevent these errors - specify the uglify option, which will enable all plugins and, as a result, fully compile your code to ES5. However, the `useBuiltIns` option will still work as before, and only include the polyfills that your target(s) need.
-
-> NOTE: Uglify has a work-in-progress "Harmony" branch to address the lack of ES6 support, but it is not yet stable. You can follow its progress in [UglifyJS2 issue #448](https://github.com/mishoo/UglifyJS2/issues/448). If you require an alternative minifier which _does_ support ES6 syntax, we recommend using [Babili](https://github.com/babel/babili).
-
### `spec`
`boolean`, defaults to `false`.
@@ -259,6 +249,47 @@ import "babel-polyfill/core-js/modules/es7.string.pad-end";
Don't add polyfills automatically per file, or transform `import "babel-polyfill"` to individual polyfills.
+### `forceAllTransforms`
+
+`boolean`, defaults to `false`.
+
+
+ Example
+
+ With Babel 7's .babelrc.js support, you can force all transforms to be run if env is set to `production`.
+
+ ```js
+ module.exports = {
+ presets: [
+ ["env", {
+ targets: {
+ chrome: 59,
+ edge: 13,
+ firefox: 50,
+ },
+ // for uglifyjs...
+ forceAllTransforms: process.env === "production"
+ }],
+ ],
+ };
+ ```
+
+
+
+> NOTE: `targets.uglify` is deprecated and will be removed in the next major in
+favor of this.
+
+By default, this preset will run all the transforms needed for the targeted
+environment(s). Enable this option if you want to force running _all_
+transforms, which is useful if the output will be run through UglifyJS or an
+environment that only supports ES5.
+
+> NOTE: Uglify has a work-in-progress "Harmony" branch to address the lack of
+ES6 support, but it is not yet stable. You can follow its progress in
+[UglifyJS2 issue #448](https://github.com/mishoo/UglifyJS2/issues/448). If you
+require an alternative minifier which _does_ support ES6 syntax, we recommend
+using [Babili](https://github.com/babel/babili).
+
---
## Examples
diff --git a/experimental/babel-preset-env/src/index.js b/experimental/babel-preset-env/src/index.js
index b48aa77704..5ee2049171 100644
--- a/experimental/babel-preset-env/src/index.js
+++ b/experimental/babel-preset-env/src/index.js
@@ -107,18 +107,42 @@ const filterItems = (list, includes, excludes, targets, defaultItems) => {
};
export default function buildPreset(context, opts = {}) {
- const validatedOptions = normalizeOptions(opts);
- const { debug, loose, moduleType, spec, useBuiltIns } = validatedOptions;
+ const {
+ debug,
+ exclude: optionsExclude,
+ forceAllTransforms,
+ include: optionsInclude,
+ loose,
+ moduleType,
+ spec,
+ targets: optionsTargets,
+ useBuiltIns,
+ } = normalizeOptions(opts);
- const targets = getTargets(validatedOptions.targets);
- const include = transformIncludesAndExcludes(validatedOptions.include);
- const exclude = transformIncludesAndExcludes(validatedOptions.exclude);
+ // TODO: remove this in next major
+ let hasUglifyTarget = false;
+
+ if (optionsTargets && optionsTargets.uglify) {
+ hasUglifyTarget = true;
+ delete optionsTargets.uglify;
+
+ console.log("");
+ console.log("The uglify target has been deprecated. Set the top level");
+ console.log("option `forceAllTransforms: true` instead.");
+ console.log("");
+ }
+
+ const targets = getTargets(optionsTargets);
+ const include = transformIncludesAndExcludes(optionsInclude);
+ const exclude = transformIncludesAndExcludes(optionsExclude);
+
+ const transformTargets = forceAllTransforms || hasUglifyTarget ? {} : targets;
const transformations = filterItems(
pluginList,
include.plugins,
exclude.plugins,
- targets,
+ transformTargets,
);
let polyfills;
diff --git a/experimental/babel-preset-env/src/normalize-options.js b/experimental/babel-preset-env/src/normalize-options.js
index 8a409525cf..51d19e1e43 100644
--- a/experimental/babel-preset-env/src/normalize-options.js
+++ b/experimental/babel-preset-env/src/normalize-options.js
@@ -57,9 +57,13 @@ export const validateBoolOption = (name, value, defaultValue) => {
export const validateLooseOption = looseOpt =>
validateBoolOption("loose", looseOpt, false);
+
export const validateSpecOption = specOpt =>
validateBoolOption("spec", specOpt, false);
+export const validateForceAllTransformsOption = forceAllTransforms =>
+ validateBoolOption("forceAllTransforms", forceAllTransforms, false);
+
export const validateModulesOption = (modulesOpt = "commonjs") => {
invariant(
modulesOpt === false ||
@@ -97,6 +101,9 @@ export default function normalizeOptions(opts) {
return {
debug: opts.debug,
exclude: validateIncludesAndExcludes(opts.exclude, "exclude"),
+ forceAllTransforms: validateForceAllTransformsOption(
+ opts.forceAllTransforms,
+ ),
include: validateIncludesAndExcludes(opts.include, "include"),
loose: validateLooseOption(opts.loose),
moduleType: validateModulesOption(opts.modules),
diff --git a/experimental/babel-preset-env/src/targets-parser.js b/experimental/babel-preset-env/src/targets-parser.js
index 504c8cc76b..637106f429 100644
--- a/experimental/babel-preset-env/src/targets-parser.js
+++ b/experimental/babel-preset-env/src/targets-parser.js
@@ -26,30 +26,27 @@ const semverMin = (first: ?string, second: string): string => {
};
const getLowestVersions = browsers => {
- return browsers.reduce(
- (all, browser) => {
- const [browserName, browserVersion] = browser.split(" ");
- const normalizedBrowserName = browserNameMap[browserName];
-
- if (!normalizedBrowserName) {
- return all;
- }
-
- try {
- // Browser version can return as "10.0-10.2"
- const splitVersion = browserVersion.split("-")[0];
- const parsedBrowserVersion = semverify(splitVersion);
-
- all[normalizedBrowserName] = semverMin(
- all[normalizedBrowserName],
- parsedBrowserVersion,
- );
- } catch (e) {}
+ return browsers.reduce((all, browser) => {
+ const [browserName, browserVersion] = browser.split(" ");
+ const normalizedBrowserName = browserNameMap[browserName];
+ if (!normalizedBrowserName) {
return all;
- },
- {},
- );
+ }
+
+ try {
+ // Browser version can return as "10.0-10.2"
+ const splitVersion = browserVersion.split("-")[0];
+ const parsedBrowserVersion = semverify(splitVersion);
+
+ all[normalizedBrowserName] = semverMin(
+ all[normalizedBrowserName],
+ parsedBrowserVersion,
+ );
+ } catch (e) {}
+
+ return all;
+ }, {});
};
const outputDecimalWarning = (decimalTargets: Array