Skip to content

Commit

Permalink
optim: specify version in @babel/plugin-transform-runtime
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
agilgur5 committed May 18, 2022
1 parent bcf3c3f commit 3db849f
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -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')
Expand All @@ -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
}]
]
}
}

0 comments on commit 3db849f

Please sign in to comment.