babel-preset-atomic

5.0.0 • Public • Published

babel-preset-atomic

This includes the babel configuration used for JavaScript packages in atom-ide-community.

Installation

npm install --save-dev babel-preset-atomic
This package also needs `@babel/core` and/or `@babel/cli`.

If using npm, the bundled babel is hoisted automatically.

If using pnpm, either add the following to your .npmrc to hoist the prettier bundled with the config

public-hoist-pattern[]=*

Or install these yourself in your devDependencies.

pnpm install -save-dev "@babel/core"
pnpm install -save-dev "@babel/cli"

Usage

Create a babel.config.json file at the root of the project with the following content:

{
  "presets": ["babel-preset-atomic"],
  "plugins": [],
  "exclude": "node_modules/**",
  "sourceMap": "inline"
}

Use babel.config.js if you need more control over the config.

babel.config.js version
let presets = ["babel-preset-atomic"]

let plugins = []

module.exports = {
  presets: presets,
  plugins: plugins,
  exclude: "node_modules/**",
  sourceMap: "inline",
}

Options

  1. keepModules

If you want to keep the ES modules as they are (not transforming import to require), set BABEL_KEEP_MODULES environment variable to true. This is useful with bundlers which need you to keep ES6 modules intact. By default the ES6 modules are transformed to ES5 (the value is false)

cross-env BABEL_KEEP_MODULES=true

To permanently set this option, you can add it to your babel config (which disables environment variable effectiveness):

{
  "presets": [
    [
      "babel-preset-atomic",
      {
        "keepModules": true,
      },
    ],
  ]
}
babel.config.js version
let presets = [
  [
    "babel-preset-atomic",
    {
      keepModules: true,
    },
  ],
]
  1. targets

To change the target of preset-env plugin. By default this is configured for Electron 11.

{
  "presets": [
    [
      "babel-preset-atomic",
      {
        "targets": {
          "electron": 9
        }
      }
    ]
  ]
}
babel.config.js version
let presets = [
  [
    "babel-preset-atomic",
    {
      targets: {
        electron: 9,
      },
    },
  ],
]
  1. addModuleExports:

Allows to require a ES6 module that has exported a single thing as default, in a ES5 fashion without require().default. This is true by default for backward compatibility with Atom packages.

{
  "presets": [
    [
      "babel-preset-atomic",
      {
        "addModuleExports": false
      }
    ]
  ]
}
babel.config.js version
let presets = [
  [
    "babel-preset-atomic",
    {
      addModuleExports: false,
    },
  ],
]
  1. addModuleExportsDefaultProperty:
{
  "presets": [
    [
      "babel-preset-atomic",
      {
        "addModuleExports": true,
        "addModuleExportsDefaultProperty": true
      }
    ]
  ]
}
babel.config.js version
let presets = [
  [
    "babel-preset-atomic",
    {
      addModuleExports: true,
      addModuleExportsDefaultProperty: true,
    },
  ],
]

Adds default property to module.exports so the ES6 module can be required in the ES6 fashion as well (by require().default). This is false by default.

  1. react

Enable "@babel/preset-react". true by default. You can also pass an object to provide more options for this plugin.

  1. flow

Enable "@babel/preset-flow". true by default. You can also pass an object to provide more options for this plugin.

  1. typescript

Enable "@babel/preset-typescript". true by default. You can also pass an object to provide more options for this plugin.

  1. removeAllUseStrict

Remove all 'use strict' from all files. Passed to babel-plugin-transform-not-strict. This is false by default.

  1. notStrictDirectiveTriggers and notStrictCommentTriggers

These specify "not strict" triggers. Passed to babel-plugin-transform-not-strict.

Behind the scenes

It includes the following presets:

  • "@babel/preset-env" (configured for electron)
  • "@babel/preset-react"
  • "@babel/preset-flow"
  • "@babel/preset-typescript"

It also includes all the proposal plugins such as:

  • "@babel/plugin-proposal-optional-chaining"
  • "@babel/plugin-proposal-nullish-coalescing-operator"
  • "@babel/plugin-proposal-export-default-from"
  • "@babel/plugin-proposal-export-namespace-from"
  • ...

It includes the plugins for compile time code generation:

  • "babel-plugin-codegen"
  • "babel-plugin-preval"

It has the preset that automatically adds default export for older Node versions (so no require().default is needed).

  • "babel-plugin-add-module-exports"

It has the plugin for removing 'use strict':

  • "babel-plugin-transform-not-strict"

Install

npm i babel-preset-atomic

DownloadsWeekly Downloads

1,374

Version

5.0.0

License

MIT

Unpacked Size

45.5 kB

Total Files

8

Last publish

Collaborators

  • atom-ide-community