From cbc27f48bdeb24f3e0793dd775ad4f8173e54b27 Mon Sep 17 00:00:00 2001 From: Matt Hinchliffe Date: Fri, 20 Jul 2018 09:02:56 +0100 Subject: [PATCH 1/7] =?UTF-8?q?Add=20programmatic=20rollup=20interface=20?= =?UTF-8?q?=20=F0=9F=90=BF=20v2.10.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/x-teaser/rollup.config.js | 10 --- components/x-teaser/rollup.js | 4 + packages/x-rollup/index.js | 106 ++---------------------- packages/x-rollup/package.json | 4 +- packages/x-rollup/src/babel-config.js | 37 +++++++++ packages/x-rollup/src/postcss-config.js | 18 ++++ packages/x-rollup/src/rollup-config.js | 58 +++++++++++++ 7 files changed, 126 insertions(+), 111 deletions(-) delete mode 100644 components/x-teaser/rollup.config.js create mode 100644 components/x-teaser/rollup.js create mode 100644 packages/x-rollup/src/babel-config.js create mode 100644 packages/x-rollup/src/postcss-config.js create mode 100644 packages/x-rollup/src/rollup-config.js diff --git a/components/x-teaser/rollup.config.js b/components/x-teaser/rollup.config.js deleted file mode 100644 index 759527f67..000000000 --- a/components/x-teaser/rollup.config.js +++ /dev/null @@ -1,10 +0,0 @@ -import xRollup from '@financial-times/x-rollup'; -import pkg from './package.json'; - -const input = 'src/Teaser.jsx'; - -const external = [ - 'dateformat' -]; - -export default xRollup({input, pkg, external}); diff --git a/components/x-teaser/rollup.js b/components/x-teaser/rollup.js new file mode 100644 index 000000000..e2c411763 --- /dev/null +++ b/components/x-teaser/rollup.js @@ -0,0 +1,4 @@ +const xRollup = require('@financial-times/x-rollup'); +const pkg = require('./package.json'); + +xRollup({ input: require.resolve('./src/Teaser.jsx'), pkg }); diff --git a/packages/x-rollup/index.js b/packages/x-rollup/index.js index 5a617f614..e5537732e 100644 --- a/packages/x-rollup/index.js +++ b/packages/x-rollup/index.js @@ -1,101 +1,11 @@ -const babel = require('rollup-plugin-babel'); -const commonjs = require('rollup-plugin-commonjs'); -const postcss = require('rollup-plugin-postcss'); -const path = require('path'); +const rollup = require('rollup'); +const rollupConfig = require('./src/rollup-config'); -const resolvePlugin = (plugin) => Array.isArray(plugin) - ? [require.resolve(plugin[0]), plugin[1]] - : require.resolve(plugin); +module.exports = async (options) => { + const config = rollupConfig(options); -const babelOptions = (targets) => ({ - include: '**/*.{js,jsx}', - plugins: [ - ['babel-plugin-transform-react-jsx', { - pragma: 'h', - useBuiltIns: true, - }], - ['babel-plugin-transform-object-rest-spread', { - // although this is stage 4, we'd have to use babel 7 to get the version - // of preset-env that supports it :/ - useBuiltIns: true, - }], - 'babel-plugin-external-helpers', - ['fast-async', { - compiler: { - noRuntime: true, - }, - }], - ].map(resolvePlugin), - - presets: targets && [ - ['babel-preset-env', { - targets, - modules: false, - exclude: ['transform-regenerator', 'transform-async-to-generator'], - }], - ].map(resolvePlugin), -}); - -module.exports = ({input, pkg, external: extraExternal = []}) => { - const external = [ - '@financial-times/x-engine', - ...extraExternal, - ]; - - const commonPlugin = commonjs({ extensions: ['.js', '.jsx'] }); - const postcssPlugin = pkg.style && postcss({ - extract: pkg.style, - modules: true, - use: [ - ['sass', { - includePaths: [path.resolve(process.cwd(), 'bower_components')] - }], - 'stylus', - 'less', - ], - }); - - return [ - { - input, - output: { - file: pkg.module, - format: 'es' - }, - external, - plugins: [ - babel(babelOptions({ node: 6 })), - postcssPlugin, - commonPlugin - ].filter(Boolean), - }, - { - input, - output: { - file: pkg.main, - format: 'cjs' - }, - external, - plugins: [ - babel(babelOptions({ node: 6 })), - postcssPlugin, - commonPlugin, - ].filter(Boolean), - }, - { - input, - output: { - file: pkg.browser, - format: 'cjs' - }, - external, - plugins: [ - babel(babelOptions({ browsers: ['ie 11'] })), - postcssPlugin, - commonPlugin, - ].filter(Boolean), - } - ]; + for (const [ input, output ] of config) { + const bundle = await rollup.rollup(input); + await bundle.write(output); + } }; - -module.exports.babelOptions = babelOptions; diff --git a/packages/x-rollup/package.json b/packages/x-rollup/package.json index 0045b55b3..849fa3bff 100644 --- a/packages/x-rollup/package.json +++ b/packages/x-rollup/package.json @@ -16,11 +16,9 @@ "babel-plugin-transform-react-jsx": "^6.24.1", "babel-preset-env": "^1.7.0", "fast-async": "^6.3.7", + "rollup": "^0.57.1", "rollup-plugin-babel": "^3.0.7", "rollup-plugin-commonjs": "^9.1.3", "rollup-plugin-postcss": "^1.6.2" - }, - "peerDependencies": { - "rollup": "^0.57.1" } } diff --git a/packages/x-rollup/src/babel-config.js b/packages/x-rollup/src/babel-config.js new file mode 100644 index 000000000..4d96b35f2 --- /dev/null +++ b/packages/x-rollup/src/babel-config.js @@ -0,0 +1,37 @@ +const resolvePlugin = (plugin) => { + if (Array.isArray(plugin)) { + return [require.resolve(plugin[0]), plugin[1]]; + } else { + return require.resolve(plugin); + } +}; + +module.exports = (targets = []) => ({ + include: '**/*.{js,jsx}', + plugins: [ + // this plugin is misleadingly named, it includes a general JSX parser and helper 🙄 + ['babel-plugin-transform-react-jsx', { + pragma: 'h', + useBuiltIns: true, + }], + // although this feature is at stage 4, we'd have to use babel 7 to get the version + // of preset-env that supports it 😖 + ['babel-plugin-transform-object-rest-spread', { + useBuiltIns: true, + }], + // don't include any of babel's internal helpers in the output + 'babel-plugin-external-helpers', + ['fast-async', { + compiler: { + noRuntime: true, + }, + }], + ].map(resolvePlugin), + presets: [ + ['babel-preset-env', { + targets, + modules: false, + exclude: ['transform-regenerator', 'transform-async-to-generator'], + }], + ].map(resolvePlugin), +}); diff --git a/packages/x-rollup/src/postcss-config.js b/packages/x-rollup/src/postcss-config.js new file mode 100644 index 000000000..5fac57486 --- /dev/null +++ b/packages/x-rollup/src/postcss-config.js @@ -0,0 +1,18 @@ +const path = require('path'); + +module.exports = (style) => { + return { + extract: style, + modules: true, + use: [ + [ + 'sass', + { + includePaths: [path.resolve(process.cwd(), 'bower_components')] + } + ], + 'stylus', + 'less' + ] + }; +}; diff --git a/packages/x-rollup/src/rollup-config.js b/packages/x-rollup/src/rollup-config.js new file mode 100644 index 000000000..a3b85dd67 --- /dev/null +++ b/packages/x-rollup/src/rollup-config.js @@ -0,0 +1,58 @@ +const babel = require('rollup-plugin-babel'); +const postcss = require('rollup-plugin-postcss'); +const commonjs = require('rollup-plugin-commonjs'); +const postcssConfig = require('./postcss-config'); +const babelConfig = require('./babel-config'); + +module.exports = ({ input, pkg }) => { + // Don't bundle any dependencies + const external = Object.keys(pkg.dependencies); + + const plugins = [ + // Convert CommonJS modules to ESM so they can be included in the bundle + commonjs({ extensions: ['.js', '.jsx'] }) + ]; + + // Add support for CSS modules (and any required transpilation) + if (pkg.style) { + const config = postcssConfig(pkg.style); + plugins.push(postcss(config)); + } + + // Pairs of input and output options + return [ + [ + { + input, + external, + plugins: [babel(babelConfig({ node: 6 })), ...plugins] + }, + { + file: pkg.module, + format: 'es' + } + ], + [ + { + input, + external, + plugins: [babel(babelConfig({ node: 6 })), ...plugins] + }, + { + file: pkg.main, + format: 'cjs' + } + ], + [ + { + input, + external, + plugins: [babel(babelConfig({ browsers: ['ie 11'] })), ...plugins] + }, + { + file: pkg.browser, + format: 'cjs' + } + ] + ]; +}; From a803abd56c5ecf98fc9ce9f878e4defd3a67f15a Mon Sep 17 00:00:00 2001 From: Matt Hinchliffe Date: Fri, 20 Jul 2018 09:04:51 +0100 Subject: [PATCH 2/7] =?UTF-8?q?Add=20programmatic=20rollup=20build=20to=20?= =?UTF-8?q?x-teaser=20=20=F0=9F=90=BF=20v2.10.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/x-teaser/package.json | 6 ++---- packages/x-rollup/rollup.template.js | 7 ------- 2 files changed, 2 insertions(+), 11 deletions(-) delete mode 100644 packages/x-rollup/rollup.template.js diff --git a/components/x-teaser/package.json b/components/x-teaser/package.json index ebcfa4cd6..8bfcb9777 100644 --- a/components/x-teaser/package.json +++ b/components/x-teaser/package.json @@ -8,8 +8,7 @@ "types": "Props.d.ts", "scripts": { "postinstall": "npm run build", - "build": "rollup -c rollup.config.js", - "start": "rollup --watch -c rollup.config.js" + "build": "node rollup.js" }, "keywords": [], "author": "", @@ -19,8 +18,7 @@ "dateformat": "^3.0.3" }, "devDependencies": { - "@financial-times/x-rollup": "file:../../packages/x-rollup", - "rollup": "^0.57.1" + "@financial-times/x-rollup": "file:../../packages/x-rollup" }, "engines": { "node": ">= 6.0.0" diff --git a/packages/x-rollup/rollup.template.js b/packages/x-rollup/rollup.template.js deleted file mode 100644 index 183e48c73..000000000 --- a/packages/x-rollup/rollup.template.js +++ /dev/null @@ -1,7 +0,0 @@ -module.exports = name => `import xRollup from '@financial-times/x-rollup'; -import pkg from './package.json'; - -const input = 'src/${name}.jsx'; - -export default xRollup({input, pkg}); -`; From 7e3263fe1a236b66b0c21605ba59b7f3fcc6ef5c Mon Sep 17 00:00:00 2001 From: Matt Hinchliffe Date: Fri, 20 Jul 2018 09:09:10 +0100 Subject: [PATCH 3/7] =?UTF-8?q?Exit=20rollup=20build=20with=20code=201=20o?= =?UTF-8?q?n=20error=20=20=F0=9F=90=BF=20v2.10.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/x-rollup/index.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/x-rollup/index.js b/packages/x-rollup/index.js index e5537732e..32d541c90 100644 --- a/packages/x-rollup/index.js +++ b/packages/x-rollup/index.js @@ -1,3 +1,5 @@ +/* eslint no-console:off */ + const rollup = require('rollup'); const rollupConfig = require('./src/rollup-config'); @@ -5,7 +7,13 @@ module.exports = async (options) => { const config = rollupConfig(options); for (const [ input, output ] of config) { - const bundle = await rollup.rollup(input); - await bundle.write(output); + try { + console.log(`Bundling ${input.input} ➡ ${output.file}…`); + const bundle = await rollup.rollup(input); + await bundle.write(output); + } catch (error) { + console.error(error); + process.exit(1); + } } }; From 1c91c7ee85e694a7c4c9ee44526ea1a1d3365cb7 Mon Sep 17 00:00:00 2001 From: Matt Hinchliffe Date: Fri, 20 Jul 2018 09:13:57 +0100 Subject: [PATCH 4/7] =?UTF-8?q?Bump=20rollup=20version=20=20=F0=9F=90=BF?= =?UTF-8?q?=20v2.10.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/x-rollup/index.js | 2 +- packages/x-rollup/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/x-rollup/index.js b/packages/x-rollup/index.js index 32d541c90..0b947898f 100644 --- a/packages/x-rollup/index.js +++ b/packages/x-rollup/index.js @@ -6,7 +6,7 @@ const rollupConfig = require('./src/rollup-config'); module.exports = async (options) => { const config = rollupConfig(options); - for (const [ input, output ] of config) { + for (const [input, output] of config) { try { console.log(`Bundling ${input.input} ➡ ${output.file}…`); const bundle = await rollup.rollup(input); diff --git a/packages/x-rollup/package.json b/packages/x-rollup/package.json index 849fa3bff..230c45eb5 100644 --- a/packages/x-rollup/package.json +++ b/packages/x-rollup/package.json @@ -16,7 +16,7 @@ "babel-plugin-transform-react-jsx": "^6.24.1", "babel-preset-env": "^1.7.0", "fast-async": "^6.3.7", - "rollup": "^0.57.1", + "rollup": "^0.63.0", "rollup-plugin-babel": "^3.0.7", "rollup-plugin-commonjs": "^9.1.3", "rollup-plugin-postcss": "^1.6.2" From 79e830a2d800e9dfbdbd7b470925ca24013d2939 Mon Sep 17 00:00:00 2001 From: Matt Hinchliffe Date: Fri, 20 Jul 2018 10:25:51 +0100 Subject: [PATCH 5/7] =?UTF-8?q?Move=20remaining=20components=20over=20to?= =?UTF-8?q?=20new=20x-rollup=20=20=F0=9F=90=BF=20v2.10.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/x-increment/package.json | 6 ++---- components/x-increment/rollup.config.js | 6 ------ components/x-increment/rollup.js | 4 ++++ components/x-interaction/package.json | 6 ++---- components/x-interaction/rollup.config.js | 12 ------------ components/x-interaction/rollup.js | 4 ++++ components/x-styling-demo/package.json | 6 ++---- components/x-styling-demo/rollup.config.js | 6 ------ components/x-styling-demo/rollup.js | 4 ++++ packages/x-rollup/src/babel-config.js | 3 ++- 10 files changed, 20 insertions(+), 37 deletions(-) delete mode 100644 components/x-increment/rollup.config.js create mode 100644 components/x-increment/rollup.js delete mode 100644 components/x-interaction/rollup.config.js create mode 100644 components/x-interaction/rollup.js delete mode 100644 components/x-styling-demo/rollup.config.js create mode 100644 components/x-styling-demo/rollup.js diff --git a/components/x-increment/package.json b/components/x-increment/package.json index 1bc39e9c9..e85cad9df 100644 --- a/components/x-increment/package.json +++ b/components/x-increment/package.json @@ -5,8 +5,7 @@ "main": "dist/Increment.cjs.js", "scripts": { "postinstall": "npm run build", - "build": "rollup -c rollup.config.js", - "start": "rollup --watch -c rollup.config.js" + "build": "node rollup.js" }, "keywords": [], "author": "", @@ -14,8 +13,7 @@ "browser": "dist/Increment.es5.js", "module": "dist/Increment.esm.js", "devDependencies": { - "@financial-times/x-rollup": "file:../../packages/x-rollup", - "rollup": "^0.57.1" + "@financial-times/x-rollup": "file:../../packages/x-rollup" }, "dependencies": { "@financial-times/x-engine": "file:../../packages/x-engine", diff --git a/components/x-increment/rollup.config.js b/components/x-increment/rollup.config.js deleted file mode 100644 index d28cf113c..000000000 --- a/components/x-increment/rollup.config.js +++ /dev/null @@ -1,6 +0,0 @@ -import xRollup from '@financial-times/x-rollup'; -import pkg from './package.json'; - -const input = 'src/Increment.jsx'; - -export default xRollup({input, pkg, external: ['@financial-times/x-interaction']}); diff --git a/components/x-increment/rollup.js b/components/x-increment/rollup.js new file mode 100644 index 000000000..b40cae65d --- /dev/null +++ b/components/x-increment/rollup.js @@ -0,0 +1,4 @@ +const xRollup = require('@financial-times/x-rollup'); +const pkg = require('./package.json'); + +xRollup({ input: require.resolve('./src/Increment.jsx'), pkg }); diff --git a/components/x-interaction/package.json b/components/x-interaction/package.json index 6bd57ae7e..960718757 100644 --- a/components/x-interaction/package.json +++ b/components/x-interaction/package.json @@ -5,8 +5,7 @@ "main": "dist/Interaction.cjs.js", "scripts": { "postinstall": "npm run build", - "build": "rollup -c rollup.config.js", - "start": "rollup --watch -c rollup.config.js" + "build": "node rollup.js" }, "keywords": [], "author": "", @@ -14,8 +13,7 @@ "browser": "dist/Interaction.es5.js", "module": "dist/Interaction.esm.js", "devDependencies": { - "@financial-times/x-rollup": "file:../../packages/x-rollup", - "rollup": "^0.57.1" + "@financial-times/x-rollup": "file:../../packages/x-rollup" }, "dependencies": { "@financial-times/x-engine": "file:../../packages/x-engine", diff --git a/components/x-interaction/rollup.config.js b/components/x-interaction/rollup.config.js deleted file mode 100644 index b71b315ea..000000000 --- a/components/x-interaction/rollup.config.js +++ /dev/null @@ -1,12 +0,0 @@ -import xRollup from '@financial-times/x-rollup'; -import pkg from './package.json'; - -const input = 'src/Interaction.jsx'; - -export default xRollup({ - input, - pkg, - external: [ - '@quarterto/short-id', - ] -}); diff --git a/components/x-interaction/rollup.js b/components/x-interaction/rollup.js new file mode 100644 index 000000000..995755af5 --- /dev/null +++ b/components/x-interaction/rollup.js @@ -0,0 +1,4 @@ +const xRollup = require('@financial-times/x-rollup'); +const pkg = require('./package.json'); + +xRollup({ input: require.resolve('./src/Interaction.jsx'), pkg }); diff --git a/components/x-styling-demo/package.json b/components/x-styling-demo/package.json index 65809d6c7..6bcc91720 100644 --- a/components/x-styling-demo/package.json +++ b/components/x-styling-demo/package.json @@ -9,16 +9,14 @@ "private": true, "scripts": { "postinstall": "npm run build", - "build": "rollup -c rollup.config.js", - "start": "rollup --watch -c rollup.config.js" + "build": "node rollup.js" }, "keywords": [], "author": "", "license": "ISC", "devDependencies": { "@financial-times/x-rollup": "file:../../packages/x-rollup", - "node-sass": "^4.9.0", - "rollup": "^0.57.1" + "node-sass": "^4.9.0" }, "dependencies": { "@financial-times/x-engine": "file:../../packages/x-engine", diff --git a/components/x-styling-demo/rollup.config.js b/components/x-styling-demo/rollup.config.js deleted file mode 100644 index 711f0559c..000000000 --- a/components/x-styling-demo/rollup.config.js +++ /dev/null @@ -1,6 +0,0 @@ -import xRollup from '@financial-times/x-rollup'; -import pkg from './package.json'; - -const input = 'src/Button.jsx'; - -export default xRollup({ input, pkg, external: ['classnames'] }); diff --git a/components/x-styling-demo/rollup.js b/components/x-styling-demo/rollup.js new file mode 100644 index 000000000..bfd8303bc --- /dev/null +++ b/components/x-styling-demo/rollup.js @@ -0,0 +1,4 @@ +const xRollup = require('@financial-times/x-rollup'); +const pkg = require('./package.json'); + +xRollup({ input: require.resolve('./src/Button.jsx'), pkg }); diff --git a/packages/x-rollup/src/babel-config.js b/packages/x-rollup/src/babel-config.js index 4d96b35f2..f84253904 100644 --- a/packages/x-rollup/src/babel-config.js +++ b/packages/x-rollup/src/babel-config.js @@ -19,8 +19,9 @@ module.exports = (targets = []) => ({ ['babel-plugin-transform-object-rest-spread', { useBuiltIns: true, }], - // don't include any of babel's internal helpers in the output + // tell Babel to not place any internal helper declarations in the output 'babel-plugin-external-helpers', + // implements async and await using syntax transformation rather than generators ['fast-async', { compiler: { noRuntime: true, From c699bde55b220e7855bffe41c2413916e29e5f77 Mon Sep 17 00:00:00 2001 From: Matt Hinchliffe Date: Fri, 20 Jul 2018 10:32:17 +0100 Subject: [PATCH 6/7] =?UTF-8?q?No=20need=20to=20resolve=20Rollup=20input?= =?UTF-8?q?=20=20=F0=9F=90=BF=20v2.10.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/x-increment/rollup.js | 2 +- components/x-interaction/rollup.js | 2 +- components/x-styling-demo/rollup.js | 2 +- components/x-teaser/rollup.js | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/components/x-increment/rollup.js b/components/x-increment/rollup.js index b40cae65d..e29c5583b 100644 --- a/components/x-increment/rollup.js +++ b/components/x-increment/rollup.js @@ -1,4 +1,4 @@ const xRollup = require('@financial-times/x-rollup'); const pkg = require('./package.json'); -xRollup({ input: require.resolve('./src/Increment.jsx'), pkg }); +xRollup({ input: './src/Increment.jsx', pkg }); diff --git a/components/x-interaction/rollup.js b/components/x-interaction/rollup.js index 995755af5..922d28e45 100644 --- a/components/x-interaction/rollup.js +++ b/components/x-interaction/rollup.js @@ -1,4 +1,4 @@ const xRollup = require('@financial-times/x-rollup'); const pkg = require('./package.json'); -xRollup({ input: require.resolve('./src/Interaction.jsx'), pkg }); +xRollup({ input: './src/Interaction.jsx', pkg }); diff --git a/components/x-styling-demo/rollup.js b/components/x-styling-demo/rollup.js index bfd8303bc..ffd6fd551 100644 --- a/components/x-styling-demo/rollup.js +++ b/components/x-styling-demo/rollup.js @@ -1,4 +1,4 @@ const xRollup = require('@financial-times/x-rollup'); const pkg = require('./package.json'); -xRollup({ input: require.resolve('./src/Button.jsx'), pkg }); +xRollup({ input: './src/Button.jsx', pkg }); diff --git a/components/x-teaser/rollup.js b/components/x-teaser/rollup.js index e2c411763..6bd63c6aa 100644 --- a/components/x-teaser/rollup.js +++ b/components/x-teaser/rollup.js @@ -1,4 +1,4 @@ const xRollup = require('@financial-times/x-rollup'); const pkg = require('./package.json'); -xRollup({ input: require.resolve('./src/Teaser.jsx'), pkg }); +xRollup({ input: './src/Teaser.jsx', pkg }); From e4f721d78fb2c4475da07670e19f3200d7034333 Mon Sep 17 00:00:00 2001 From: Matt Hinchliffe Date: Tue, 24 Jul 2018 12:10:47 +0100 Subject: [PATCH 7/7] =?UTF-8?q?Prettify=20x-rollup=20module=20=20?= =?UTF-8?q?=F0=9F=90=BF=20v2.10.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/x-rollup/src/babel-config.js | 71 ++++++++++++++------------- 1 file changed, 38 insertions(+), 33 deletions(-) diff --git a/packages/x-rollup/src/babel-config.js b/packages/x-rollup/src/babel-config.js index f84253904..424d3bfbc 100644 --- a/packages/x-rollup/src/babel-config.js +++ b/packages/x-rollup/src/babel-config.js @@ -1,38 +1,43 @@ -const resolvePlugin = (plugin) => { - if (Array.isArray(plugin)) { - return [require.resolve(plugin[0]), plugin[1]]; - } else { - return require.resolve(plugin); - } -}; - module.exports = (targets = []) => ({ include: '**/*.{js,jsx}', plugins: [ - // this plugin is misleadingly named, it includes a general JSX parser and helper 🙄 - ['babel-plugin-transform-react-jsx', { - pragma: 'h', - useBuiltIns: true, - }], - // although this feature is at stage 4, we'd have to use babel 7 to get the version - // of preset-env that supports it 😖 - ['babel-plugin-transform-object-rest-spread', { - useBuiltIns: true, - }], - // tell Babel to not place any internal helper declarations in the output - 'babel-plugin-external-helpers', - // implements async and await using syntax transformation rather than generators - ['fast-async', { - compiler: { - noRuntime: true, - }, - }], - ].map(resolvePlugin), + // this plugin is not React specific! It includes a general JSX parser and helper 🙄 + [ + require.resolve('babel-plugin-transform-react-jsx'), + { + pragma: 'h', + useBuiltIns: true + } + ], + // Although this feature is at stage 4, we'd have to use babel 7 to get the version + // of preset-env that actually supports it 😖 + [ + require.resolve('babel-plugin-transform-object-rest-spread'), + { + useBuiltIns: true + } + ], + // Instruct Babel to not include any internal helper declarations in the output + require.resolve('babel-plugin-external-helpers'), + // Implements async/await using syntax transformation rather than generators which require + // a huge runtime for browsers which do not natively support them. + [ + require.resolve('fast-async'), + { + compiler: { + noRuntime: true + } + } + ] + ], presets: [ - ['babel-preset-env', { - targets, - modules: false, - exclude: ['transform-regenerator', 'transform-async-to-generator'], - }], - ].map(resolvePlugin), + [ + require.resolve('babel-preset-env'), + { + targets, + modules: false, + exclude: ['transform-regenerator', 'transform-async-to-generator'] + } + ] + ] });