项目作者: selfpub-org

项目描述 :
Selfpub's babel preset for transforming JavaScript
高级语言: JavaScript
项目地址: git://github.com/selfpub-org/babel-preset.git
创建时间: 2018-10-10T07:49:24Z
项目社区:https://github.com/selfpub-org/babel-preset

开源协议:MIT License

下载


@selfpub/babel-preset

@selfpub/babel-preset"">NpmLicense
@selfpub/babel-preset"">NPM version

Selfpub’s config for Babel transforms.

Install

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

With Yarn

  1. yarn add --dev --exact @babel/core @selfpub/babel-preset

With npm

  1. npm install @babel/core @selfpub/babel-preset --save-dev --save-exact

If you have dependencies on babel 6 use this way for install

With Yarn

  1. yarn add --dev @babel/core @selfpub/babel-preset 'babel-core@^7.0.0-bridge' @babel/core

With npm

  1. npm install @babel/core @selfpub/babel-preset 'babel-core@^7.0.0-bridge' --save-dev --save-exact

Usage

Then, in your Babel configuration, set this package as the babel preset you’d like to use:

  1. {
  2. "presets": [
  3. "@selfpub/babel-preset"
  4. ]
  5. }

Via CLI

  1. $ babel script.js --presets @selfpub/babel-preset

Via Node API

  1. require('@babel/core').transform('code', {
  2. presets: ['@selfpub/babel-preset'],
  3. });

Presets

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

  • @selfpub/babel-preset: A preset to use for JavaScript that is meant to run in browsers.
    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:

      1. {
      2. "babel": {
      3. "presets": [
      4. ["@selfpub/babel-preset", {"modules": false}]
      5. ]
      6. }
      7. }
    • browsers, a browserslist string or array, which specifies which browsers to transpile for. Defaults to the list found in browsers.js.

      Defaults values:

      1. [
      2. "last 2 Chrome versions",
      3. "not Chrome < 60",
      4. "last 2 Safari versions",
      5. "not Safari < 10.1",
      6. "last 2 iOS versions",
      7. "not iOS < 10.3",
      8. "last 2 Firefox versions",
      9. "not Firefox < 54",
      10. "last 2 Edge versions",
      11. "not Edge < 15"
      12. ]

      Config example:

      1. {
      2. "babel": {
      3. "presets": [
      4. ["@selfpub/babel-preset", {
      5. "browsers": ["last 5 versions"]
      6. }]
      7. ]
      8. }
      9. }
    • debug, a boolean (defaults to false) to turn on @babel/preset-env debugging

      1. {
      2. "babel": {
      3. "presets": [
      4. ["@selfpub/babel-preset", {
      5. "debug": true
      6. }]
      7. ]
      8. }
      9. }