├── .gitignore ├── .eslintrc.json ├── bin └── list-required.js ├── lib ├── presets │ ├── es2016.js │ ├── es2017.js │ └── es2015.js └── index.js ├── index.js ├── LICENSE ├── package.json └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "node": true 4 | }, 5 | "extends": "eslint:recommended" 6 | } 7 | -------------------------------------------------------------------------------- /bin/list-required.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | /* eslint no-console: 0 */ 4 | 5 | 'use strict' 6 | 7 | console.log(require('../lib')) 8 | -------------------------------------------------------------------------------- /lib/presets/es2016.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | var features = require('es-feature-detect') 4 | 5 | module.exports = [ 6 | !features.exponentiationOperator && 'transform-exponentiation-operator' 7 | ] 8 | -------------------------------------------------------------------------------- /lib/index.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | var requiredPlugins = [] 4 | .concat(require('./presets/es2015')) 5 | .concat(require('./presets/es2016')) 6 | .concat(require('./presets/es2017')) 7 | .filter(Boolean) 8 | 9 | module.exports = requiredPlugins 10 | -------------------------------------------------------------------------------- /lib/presets/es2017.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | var features = require('es-feature-detect') 4 | 5 | module.exports = [ 6 | !features.trailingFunctionCommas && 'syntax-trailing-function-commas', 7 | !features.asyncFunctions && 'transform-async-to-generator' 8 | ] 9 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | var options = { 4 | async: false, 5 | asyncGenerators: false, 6 | loose: false, 7 | spec: false 8 | } 9 | 10 | var requiredPlugins = require('./lib') 11 | 12 | module.exports = { 13 | plugins: requiredPlugins.map(function (name) { 14 | return [require('babel-plugin-' + name), options] 15 | }) 16 | } 17 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 2 | Version 2, December 2004 3 | 4 | Copyright (C) 2004 Sam Hocevar 5 | 6 | Everyone is permitted to copy and distribute verbatim or modified 7 | copies of this license document, and changing it is allowed as long 8 | as the name is changed. 9 | 10 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 11 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 12 | 13 | 0. You just DO WHAT THE FUCK YOU WANT TO. 14 | -------------------------------------------------------------------------------- /lib/presets/es2015.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | var features = require('es-feature-detect') 4 | 5 | module.exports = [ 6 | !features.templateLiterals && 'transform-es2015-template-literals', 7 | !(features.octalIntegerLiterals && features.unicodeLiterals) && 'transform-es2015-literals', 8 | !features.functionName && 'transform-es2015-function-name', 9 | !features.arrowFunctions && 'transform-es2015-arrow-functions', 10 | !features.blockLevelFunctionDeclaration && 'transform-es2015-block-scoped-functions', 11 | !features.class && 'transform-es2015-classes', 12 | !features.objectSuper && 'transform-es2015-object-super', 13 | !(features.shorthandProperties && features.shorthandMethods) && 'transform-es2015-shorthand-properties', 14 | 'transform-es2015-duplicate-keys', 15 | !features.computedProperties && 'transform-es2015-computed-properties', 16 | !features.forOf && 'transform-es2015-for-of', 17 | !features.stickyRegExp && 'transform-es2015-sticky-regex', 18 | !features.unicodeRegExp && 'transform-es2015-unicode-regex', 19 | !features.const && 'check-es2015-constants', 20 | !features.spreadOperator && 'transform-es2015-spread', 21 | !(features.defaultParameters && features.restParameters) && 'transform-es2015-parameters', 22 | !features.destructuring && 'transform-es2015-destructuring', 23 | !(features.const && features.let) && 'transform-es2015-block-scoping', 24 | !features.typeofSymbol && 'transform-es2015-typeof-symbol', 25 | !features.moduleExport && 'transform-es2015-modules-commonjs', 26 | !features.generators && 'transform-regenerator' 27 | ] 28 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "babel-preset-latest-minimal", 3 | "version": "1.1.2", 4 | "description": "Babel preset including only needed ES2015+ plugins", 5 | "keywords": [ 6 | "babel", 7 | "es2015", 8 | "es2016", 9 | "es2017", 10 | "feature detection", 11 | "latest", 12 | "plugin", 13 | "preset" 14 | ], 15 | "license": "WTFPL", 16 | "author": "Gabriel Montes ", 17 | "main": "index.js", 18 | "bin": { 19 | "babel-node-list-required": "bin/list-required.js" 20 | }, 21 | "repository": "gabmontes/babel-preset-latest-minimal", 22 | "dependencies": { 23 | "babel-plugin-check-es2015-constants": "^6.8.0", 24 | "babel-plugin-syntax-trailing-function-commas": "^6.13.0", 25 | "babel-plugin-transform-async-to-generator": "^6.8.0", 26 | "babel-plugin-transform-es2015-arrow-functions": "^6.8.0", 27 | "babel-plugin-transform-es2015-block-scoped-functions": "^6.8.0", 28 | "babel-plugin-transform-es2015-block-scoping": "^6.14.0", 29 | "babel-plugin-transform-es2015-classes": "^6.14.0", 30 | "babel-plugin-transform-es2015-computed-properties": "^6.8.0", 31 | "babel-plugin-transform-es2015-destructuring": "^6.9.0", 32 | "babel-plugin-transform-es2015-duplicate-keys": "^6.8.0", 33 | "babel-plugin-transform-es2015-for-of": "^6.8.0", 34 | "babel-plugin-transform-es2015-function-name": "^6.9.0", 35 | "babel-plugin-transform-es2015-literals": "^6.8.0", 36 | "babel-plugin-transform-es2015-modules-commonjs": "^6.14.0", 37 | "babel-plugin-transform-es2015-object-super": "^6.8.0", 38 | "babel-plugin-transform-es2015-parameters": "^6.11.4", 39 | "babel-plugin-transform-es2015-shorthand-properties": "^6.8.0", 40 | "babel-plugin-transform-es2015-spread": "^6.8.0", 41 | "babel-plugin-transform-es2015-sticky-regex": "^6.8.0", 42 | "babel-plugin-transform-es2015-template-literals": "^6.8.0", 43 | "babel-plugin-transform-es2015-typeof-symbol": "^6.8.0", 44 | "babel-plugin-transform-es2015-unicode-regex": "^6.11.0", 45 | "babel-plugin-transform-exponentiation-operator": "^6.8.0", 46 | "babel-plugin-transform-regenerator": "^6.14.0", 47 | "es-feature-detect": "^1.0.0" 48 | }, 49 | "devDependencies": { 50 | "eslint": "^4.1.0" 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # babel-preset-latest-minimal 2 | 3 | Babel preset including only needed ES2015+ plugins using feature detection. 4 | 5 | ## Install 6 | 7 | ```bash 8 | $ npm install --save-dev babel-preset-latest-minimal 9 | ``` 10 | 11 | ## Usage 12 | 13 | Add preset to your `.babelrc` file: 14 | 15 | ```json 16 | { 17 | "presets": ["latest-minimal"] 18 | } 19 | ``` 20 | 21 | ## Command-line 22 | 23 | For convenience, the module provides a command line utility to list the current plugins needed according to the version of node present in the system. 24 | 25 | ```bash 26 | $ node --version 27 | v5.12.0 28 | $ babel-node-list-required 29 | [ 'transform-es2015-object-super', 30 | 'transform-es2015-shorthand-properties', 31 | 'transform-es2015-duplicate-keys', 32 | 'transform-es2015-sticky-regex', 33 | 'transform-es2015-unicode-regex', 34 | 'transform-es2015-spread', 35 | 'transform-es2015-parameters', 36 | 'transform-es2015-destructuring', 37 | 'transform-es2015-modules-commonjs', 38 | 'transform-exponentiation-operator', 39 | 'syntax-trailing-function-commas', 40 | 'transform-async-to-generator' ] 41 | ``` 42 | 43 | ## Motivation 44 | 45 | When using the fantastic [Babel](http://babeljs.io/) transpiler in building web applications with the latest and greatest ECMAScript features, it is advisable and safer to include all plugins from [`babel-preset-latest`](https://github.com/babel/babel/tree/master/packages/babel-preset-latest) due to the fact that the runtime environment (the browser) is unknown at build-time. Anyway, when developing a Node.JS or an Electron application, the environment is controlled and Babel plugins could be hand-picked to transpile only the features not supported. 46 | 47 | Most of the presets I came across before developing this one rely basically on the node version and enable an arbitrary set of plugins. Deciding what to enable based on the version of node is like the old user-agent sniffing technique we all learned to avoid in favor of **feature detection**. 48 | 49 | So, long story short, the solution was to took all official plugins in Babel's `babel-preset-latest` and enable only those needed because the environment is not supporting a specific feature. In addition, this approach allows the developer to change the version of node/electron and this plugin will update the plugins list accordingly. Nothing is hadrcoded, no magic, no arbitrary decisions! 50 | 51 | ## Contribute 52 | 53 | Are plugins missing? Is there any issue with the feature detection? Let me know by sending a PR or filing an issue! 54 | 55 | ## License 56 | 57 | WTFPL 58 | --------------------------------------------------------------------------------