From 665915214510873351b5136e4afffff76e021024 Mon Sep 17 00:00:00 2001 From: Jack Turnbull Date: Wed, 18 Dec 2019 20:53:59 +0000 Subject: [PATCH] build: relax transpilation for es modules (#3337) * build: relax transpilation for es modules ES module output currently includes regenerator runtime functions which can block strict content security policies. For an ES module output this isn't required because any runtime supporting ES modules will also support async/await natively. It is also highly likely that users of the ES module would also be performing their own transipliation of async/await and we should not make assumptions on their behalf (some may prefer promises to regenerator, for example). This commit splits the babel config into two; an unchanged one for the UMD output, and another for module output. * build: override babel settings from plugin --- config/babel/babel.config.cjs | 11 ----------- config/rollup/rollup.config.js | 32 +++++++++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 12 deletions(-) delete mode 100644 config/babel/babel.config.cjs diff --git a/config/babel/babel.config.cjs b/config/babel/babel.config.cjs deleted file mode 100644 index f2c264e1d..000000000 --- a/config/babel/babel.config.cjs +++ /dev/null @@ -1,11 +0,0 @@ -module.exports = { - presets: [ - '@babel/preset-typescript', - ['@babel/preset-env', { modules: false }], - '@babel/preset-react', - ], - plugins: [ - '@babel/plugin-transform-runtime', - '@babel/plugin-proposal-class-properties', - ], -} diff --git a/config/rollup/rollup.config.js b/config/rollup/rollup.config.js index 4c5734ac6..84e4ec532 100644 --- a/config/rollup/rollup.config.js +++ b/config/rollup/rollup.config.js @@ -90,7 +90,37 @@ function configure(pkg, env, target) { runtimeHelpers: true, include: [`packages/${pkg.name}/src/**`], extensions: ['.js', '.ts'], - configFile: './config/babel/babel.config.cjs', + presets: [ + '@babel/preset-typescript', + [ + '@babel/preset-env', + isUmd + ? { modules: false } + : { + exclude: [ + '@babel/plugin-transform-regenerator', + '@babel/transform-async-to-generator', + ], + modules: false, + targets: { + esmodules: true, + }, + }, + ], + '@babel/preset-react', + ], + plugins: [ + [ + '@babel/plugin-transform-runtime', + isUmd + ? {} + : { + regenerator: false, + useESModules: true, + }, + ], + '@babel/plugin-proposal-class-properties', + ], }), // Register Node.js globals for browserify compatibility.