crystal-ball/babel-base

View on GitHub
babel.config.js

Summary

Maintainability
A
0 mins
Test Coverage
'use strict'

module.exports = {
  presets: [
    [
      // Automatically use the minimum set of syntax and polyfill transforms to
      // meet target environment using browserslist config.
      '@babel/preset-env',
      {
        // Transform modules to common js in test for Jest
        // Disable module transformation in dev and prod builds to allow
        // webpack to smart-manage modules.
        modules: 'commonjs',
        // Transforms the core-js and regenerator-runtime imports in index.js
        // to only the polyfills needed for the target environments
        useBuiltIns: 'entry',
        // Configure core-js version used for polyfills. Do not automatically
        // polyfill *proposals* with { version: 3, proposals: true }, if a
        // consumer needs additional proposals polyfilled they can include them
        // in the entry
        corejs: 3,
      },
    ],

    // Enable TypeScript usage 🔐
    '@babel/preset-typescript',
  ],
  plugins: [
    // Transform Runtime will transform inline Babel helper fns to imports from
    //   @babel/runtime
    // Passing useESModules disables running helper imports through the common
    //   js module transform and allows webpack to manage the esm
    // Passing corejs configs will use imports from @babel/runtime-corejs3
    //   instead of global polyfills (this should be set for libraries but is
    //   optional for applications)
    // Do not set corejs, that will use module scoped polyfilled helpers, but
    //   env is polyfilled so we would double polyfill
    [
      '@babel/plugin-transform-runtime',
      {
        useESModules: false,
        // https://github.com/babel/babel/issues/10261
        // eslint-disable-next-line
        version: require('@babel/helpers/package.json').version,
      },
    ],
  ],
}