From 3db849ff500a3f2f947d46a6100c38aa5b96ac8e Mon Sep 17 00:00:00 2001 From: Anton Gilgur Date: Mon, 16 May 2022 12:56:15 -0400 Subject: [PATCH] optim: specify version in @babel/plugin-transform-runtime - the default is 7.0.0, but we are on a newer version, so we can use newer / more optimized helpers - `createSuper` now seems to be used, which required 7.9.0: https://github.com/babel/babel/blob/9199565fa08d840c8f1cc86c1b22be119b538f2f/packages/babel-helpers/src/helpers.ts#L624 - this seems to replace the `possibleConstructorReturn` and `getPrototypeOf` helpers - roughly ~6% minified size decrease as a result! - change babel.config.js's caching to include @babel/runtime's version since we would need to rebuild if it changes --- babel.config.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/babel.config.js b/babel.config.js index 25c6bf7..823011c 100644 --- a/babel.config.js +++ b/babel.config.js @@ -1,7 +1,12 @@ +const pkgJson = require('./package.json') + +const runtimeVersion = pkgJson.dependencies['@babel/runtime'] +// eslint-disable-next-line dot-notation -- this conflicts with tsc, possibly due to outdated ESLint +const NODE_ENV = process.env['NODE_ENV'] + /** @type {import('@babel/core').ConfigFunction} */ module.exports = api => { - // eslint-disable-next-line dot-notation -- this conflicts with tsc, possibly due to outdated ESLint - api.cache.using(() => process.env['NODE_ENV']) // cache based on NODE_ENV + api.cache.using(() => NODE_ENV + '_' + runtimeVersion) // cache based on NODE_ENV and runtimeVersion // normally use browserslistrc, but for Jest, use current version of Node const isTest = api.env('test') @@ -24,7 +29,10 @@ module.exports = api => { ], plugins: [ // used with @rollup/plugin-babel - '@babel/plugin-transform-runtime' + ['@babel/plugin-transform-runtime', { + regenerator: false, // not used, and would prefer babel-polyfills over this anyway + version: runtimeVersion // @babel/runtime's version + }] ] } }