Giter Site home page Giter Site logo

babel-config-ahd's Introduction

babel-preset-ahd

A babel preset for transforming your JavaScript for AHDCreative.

Currently contains transforms for all stage 4 (ES2018) and stage 3 syntax that is permitted in the AHD Style Guide. Please note that if usage of a stage 3 proposal is not explicitly mentioned in the AHD Style Guide, then it will not be enabled here. Additionally, stage 4 syntax that is excluded is as follows:

  • generators: regenerator-runtime is too heavyweight for our use.
  • async/await: regenerator-runtime is too heavyweight for our use, and async-to-promises is not yet complete enough to be safely used.
  • async iterators: depends on both generators and async functions
  • lifted template literal restrictions: we do not use tagged template literals, nor implement custom DSLs, otherwise we would enable this.

Install

$ npm install --save-dev @ahdcreative/babel-preset-ahd

Usage

Via .babelrc (Recommended)

.babelrc

{
  "presets": ["ahd"]
}

Via CLI

$ babel script.js --presets ahd

Via Node API

require('@babel/core').transform('code', {
  presets: ['ahd']
});

Targeting Environments

This module uses @babel/preset-env to target specific environments.

Please refer to @babel/preset-env#targets for a list of available options.

For a list of browsers please see browserlist.

You may override our default list of targets by providing your own targets key.

{
  "presets": [["ahd", {
    "targets": {
      "chrome": 50,
      "ie": 11,
      "firefox": 45
    }
  }]]
}

The following transpiles only for Node v6.

{
  "presets": [["ahd", {
    "targets": {
      "node": 6
    }
  }]]
}

If you wish, you can also inherit our default list of browsers and extend them using additionalTargets.

{
  "presets": [["ahd", {
    "additionalTargets": {
      "chrome": 42,
      "ie": 8
    }
  }]]
}

You may override our default debug option by providing your own debug key.

{
  "presets": [["ahd", {
    "debug": true
  }]]
}

React Development Mode

When process.env.NODE_ENV is 'development', the development mode will be set for @babel/preset-react.

You may override our default development option by providing your own boolean development key.

{
  "presets": [["ahd", {
    "development": false
  }]]
}

React PropTypes removal

This preset can be configured to remove propTypes using babel-plugin-transform-react-remove-prop-types with the following default options:

To enable this transformation with the default options, set the removePropTypes option to true:

{
  "presets": [["ahd", {
    "removePropTypes": true
  }]]
}

The default options that will be used are:

{
  mode: 'wrap',
  additionalLibraries: ['ahd-prop-types'],
  ignoreFilenames: ['node_modules'],
}

Default options can be overridden using the removePropTypes option. These options will be shallow-merged with the defaults:

{
  "presets": [["ahd", {
    "removePropTypes": {
      "mode": "remove"
    }
  }]]
}

For example, if you are using this plugin in a deployable app, you might want to use the remove mode for your production build (and disable this transform entirely in development for optimal build speeds).

Classes loose mode

By default, this preset will compile classes in normal mode. This is safer, but comes with a bundle size and runtime overhead. To compile classes in loose mode, set the looseClasses option to true:

{
  "presets": [["ahd", {
    "looseClasses": true,
  }]]
}

The risks of enabling loose classes are outlined in the Babel docs.

Specifying a babel runtime version

By default @babel/plugin-transform-runtime will assume the oldest version of the runtime to avoid importing helpers that don't exist which would fail at runtime. This can result in newer helpers being inlined into modules (ex. objectSpread2) which increases bundle size.

To avoid this you can configure the preset to use the same version of the runtime that's installed in your package.json.

ex. If package.json has "@babel/runtime": "^7.5.5" then you can use:

{
  "presets": [["ahd", {
    "runtimeVersion": "7.5.5",
  }]]
}

Note that this will result in a runtime breakage if the version passed into the airbnb preset is newer than the version of the babel runtime actually being used at build time.

Disabling plugin-transform-runtime

You can use the transformRuntime option to disable @babel/plugin-transform-runtime. Specifying false will disable the plugin. This option defaults to true.

Specifying module transforms

You can use the modules option to enable transformation of modules given to this preset:

{
  "presets": [["ahd", {
    "modules": "auto"
  }]]
}

Both true and the option default auto will not transform modules if ES6 module syntax is already supported by the environment, or "commonjs" otherwise. false will not transform modules.

You can use the runtimeHelpersUseESModules option to prevent transformation of runtime helpers to CommonJS modules.

{
  "presets": [["ahd", {
    "runtimeHelpersUseESModules": true
  }]]
}

true will not transform runtime helpers to CommonJS modules. false will transform runtime helpers to CommonJS modules. The option defaults to true if modules is set to false, and false otherwise.

babel-config-ahd's People

Contributors

renovate[bot] avatar

Watchers

James Cloos avatar Luca avatar

babel-config-ahd's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

npm
package.json
  • @babel/helper-plugin-utils ^7.19.0
  • @babel/plugin-proposal-nullish-coalescing-operator ^7.18.6
  • @babel/plugin-proposal-numeric-separator ^7.18.6
  • @babel/plugin-proposal-object-rest-spread ^7.19.4
  • @babel/plugin-proposal-optional-catch-binding ^7.18.6
  • @babel/plugin-proposal-optional-chaining ^7.18.9
  • @babel/plugin-transform-classes ^7.19.0
  • @babel/plugin-transform-exponentiation-operator ^7.18.6
  • @babel/plugin-transform-member-expression-literals ^7.18.6
  • @babel/plugin-transform-property-literals ^7.18.6
  • @babel/plugin-transform-property-mutators ^7.18.6
  • @babel/plugin-transform-runtime ^7.19.6
  • @babel/plugin-transform-template-literals ^7.18.9
  • @babel/preset-env ^7.19.4
  • @babel/preset-react ^7.18.6
  • babel-plugin-transform-react-remove-prop-types ^0.4.24
  • @babel/core ^7.19.6
  • @babel/runtime ^7.20.0
  • eslint ^8.26.0
  • @ahdcreative/eslint-config-ahd-base ^1.0.7
  • eslint-plugin-import ^2.26.0
  • safe-publish-latest ^2.0.0
  • @babel/core ^7.19.6
  • @babel/runtime ^7.20.0
nvm
.nvmrc
  • node 16.18
travis
.travis.yml
  • node 16.18

  • Check this box to trigger a request for Renovate to run again on this repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.