1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-31 02:49:56 +02:00

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
This commit is contained in:
Jack Turnbull
2019-12-18 20:53:59 +00:00
committed by Ian Storm Taylor
parent 40617e4f1a
commit 6659152145
2 changed files with 31 additions and 12 deletions

View File

@@ -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',
],
}

View File

@@ -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.