Détail du package

babel-preset-shopify

Shopify4.8kMITobsolète21.0.0

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

Shopify's org-wide Babel preset

readme

babel-preset-shopify

NPM version

Shopify’s org-wide set of Babel transforms.

Usage

Install this package, as well as the parts of Babel you wish to use:

With Yarn

yarn add --dev --exact babel-core babel-preset-shopify

With npm

npm install babel-core babel-preset-shopify --save-dev --save-exact

Then, in your Babel configuration (which should be under the babel key of your package.json), set this package as the babel preset you’d like to use:

{
  "babel": {
    "presets": ["babel-preset-shopify/web"]
  }
}

Presets

This packages comes with several different presets for you to use, depending on your project:

  • babel-preset-shopify: The same as babel-preset-shopify/web.

  • babel-preset-shopify/web: A preset to use for JavaScript that is meant to run in browsers. It compiles down features to only those supported by browsers that you have specified in your browserslist config. Note that many modern JavaScript features, like Maps, Sets, for of loops, and more, require runtime polyfills (we recommend @shopify/polyfills, as our web and node configs will reduce these imports to the set of features needed to polyfill your target environment).

    This preset accepts an options object. The following options are allowed:

    • modules, a boolean indicating whether native ES2015 modules should be transpiled to CommonJS equivalents. Set this option to false when you are using a bundler like Rollup or Webpack 2:

      {
        "babel": {
          "presets": [
            ["babel-preset-shopify/web", {"modules": false}]
          ]
        }
      }
    • browsers, a browserslist string or array, which specifies which browsers to transpile for. We recommend setting your target browsers using a browserslist key in package.json, as that method will automatically be used by all browserslist-compatible tools.

      {
        "babel": {
          "presets": [
            ["babel-preset-shopify/web", {
              "browsers": ["last 3 versions"]
            }]
          ]
        }
      }
    • typescript, a boolean (defaults to false) to turn on @babel/preset-typescript and other plugins that allow babel to read typescript files directly.

    • inlineEnv, a boolean (defaults to false) to automatically replace process.env.<VAR> statements with the corresponding environment variable.

    • debug, a boolean (defaults to false) to turn on @babel/preset-env debugging.

    • corejs, a number of string that will be used to set the corejs version to use

    • useBuiltIns, a string that is passed to the useBuiltIns option of @babel/preset-env

  • babel-preset-shopify/node: This preset transpiles features to a specified version of Node, defaulting to the currently active version. It accepts an options object. The modules, typescript, inlineEnv,debug, corejs and useBuiltIns options do the same thing they do in babel-preset-shopify/web, detailed above. You can also pass a version of Node to target during transpilation using the version option:

    {
      "babel": {
        "presets": [
          ["babel-preset-shopify/node", {
            "modules": false,
            "version": 4
          }]
        ]
      }
    }
  • babel-preset-shopify/react: Adds plugins that transform React (including JSX). You can use this preset with the babel-preset-shopify/web or babel-preset-shopify/node configuration.

    This preset accepts an options object.

    • hot : Will automatically add plugins to enable hot reloading of React components. Note that this requires you to have a recent version of react-hot-loader installed as a dependency in your project.
    • pragma : Replace the function used when compiling JSX expressions. Defaults to React.createElement.
    • pragmaFrag: Replace the function used when compiling JSX fragment expressions. Defaults to React.Fragment.
    {
      "babel": {
        "presets": [
          ["babel-preset-shopify/react", {"hot": true}]
        ]
      }
    }

As noted above, you can include multiple of these presets together. Some common recipes are shown below:

// A React project without any server component, using sprockets-commoner for bundling
{
  "babel": {
    "presets": [
      "babel-preset-shopify/web",
      "babel-preset-shopify/react"
    ]
  }
}

// A Node project using Rollup to create a single bundle
{
  "babel": {
    "presets": [
      ["babel-preset-shopify/node", {"modules": false}]
    ]
  }
}

changelog

Changelog

21.0.0

Added

  • Added support for null coalescing and optional chaining operators [#48]

Updated

  • @babel/core, @babel/preset-env, presets, and plugins updated to the latest 7.7.x versions [#47]

20.1.0 - 2019-09-24

  • Pass browsers web preset config string directly into babel-preset-env's targets option, so that if it is unset we shall read honor browserslist config in package.json / .browserslistrc

20.0.0 - 2019-06-03

  • Add babel-plugin-dynamic-import-node to the node preset. This was originally added in 19.1.0 then reverted in 19.1.1 as it was a breaking change in some circumstances

19.1.1 - 2019-06-03

  • Revert Adding babel-plugin-dynamic-import-node to the node preset as this may be a breaking change in some circumstances

19.1.0 - 2019-05-29

  • Added typescript option to node and web presets to allow babel to read typescript files when set to true.
  • Added babel-plugin-dynamic-import-node to the node preset
  • Removed @babel/plugin-proposal-optional-catch-binding because it is already handled by @babel/preset-env if you specify an environment where it is needed.

19.0.1 - 2019-05-23

  • Added @babel/plugin-proposal-optional-catch-binding to node and web presets

19.0.0 - 2019-05-06

  • Switched the default useBuiltIns option back to entry, since it has a smaller bundle impact on large applications

18.1.1 - 2019-05-03

  • web preset now accepts a useBuiltIn value (default = usage)

18.1.0 - 2019-04-22

Added

  • node and web presets now accept a corejs option (default = 2)

18.0.0 - 2019-03-19

Changed

  • node and web presets now use useBuiltIns: 'usage' for including corejs polyfills.

17.0.1 - 2019-01-09

Fixed

  • Honor the envName defined in your babel config.

17.0.0 - 2019-01-03

Changed

  • All presets now only work with Babel version 7 or greater.
  • browsers are no longer hardcoded to those supported by Shopify’s admin for the purposes of the shopify/web preset. You must provide a browserslist-compatible configuration within your project, which will be used automatically when running Babel with this preset. Projects can use @shopify/browserslist-config to get the same support as Shopify’s admin.
  • The shopify/web preset no longer includes plugins for Stage 3 features. The only non-standard features included in this preset are class properties and dynamic imports.

Removed

  • Removed shopify/flow preset since it is no longer used by most projects at Shopify.

Added

  • The shopify/react preset now accepts a pragmaFrag option for specifying the component to use in JSX fragment expressions.

16.7.0 - 2018-12-18

Changed

  • Removed babel-plugin-transform-react-pure-to-component.

16.6.0 - 2018-10-11

Changed

  • Updated several babel plugin dependencies:
    • babel-plugin-transform-inline-environment-variables 0.1.1 => 0.4.3
    • babel-plugin-transform-object-rest-spread 6.23.0 => 6.26.0
    • babel-preset-env 1.5.2 => 1.7.0.

Internals

  • Switch from Circle CI to Travis.

16.5.0 - 2018-05-01

Internals

  • Added publishConfig to fix deployments.

16.4.0 - 2018-05-01

Added

  • shopify/react preset now accepts an additional option, pragma. Defaults to React.createElement.

16.3.0 - 2018-03-14

Added

  • shopify/web and shopify/node now accept an additional option, debug. When passed, this enables babel-preset-env's debugging to show why transforms are being included in a project. Defaults to false (current behaviour).

16.2.0 - 2017-08-23

Added

  • Added babel-plugin-syntax-dynamic-import to the web config.

16.1.0 - 2017-06-08

Added

  • Added a Babel plugin to remove testID props in non-test environments.

16.0.2 - 2017-02-18

Updated

  • Integrated bugfix from most recent version of babel-plugin-transform-react-pure-to-component.

16.0.1 - 2017-02-17

Fixed

  • shopify/web and shopify/node now correctly default the modules option to 'commonjs' instead of true.

16.0.0 - 2017-02-07

Added

  • shopify/react now includes a hot option to enable plugins related to hot reloading (react-hot-loader and react-pure-to-component).
  • shopify/react now includes plugins in development that add additional information for debugging purposes, and plugins in production that offer some performance optimizations.
  • shopify/web now accepts an additional option, browsers (an array of browserslist strings) which specifies what browsers to transpile for (defaults to the browsers supported by Shopify’s admin).

Updated

  • shopify/web and shopify/node presets now use babel-preset-env to transpile only the features needed for the target environment.
  • Updated all versions of dependend-on plugins and presets.

15.0.1

  • Initial move from combined javascript repo.