JSPM

babel-plugin-transform-imports-api

1.0.0
    • ESM via JSPM
    • ES Module Entrypoint
    • Export Map
    • Keywords
    • License
    • Repository URL
    • TypeScript Types
    • README
    • Created
    • Published
    • Downloads 12983
    • Score
      100M100P100Q139088F
    • License MIT

    Convert import default package API to modular reference to reduce package size and transforms member style imports.

    Package Exports

    • babel-plugin-transform-imports-api

    This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (babel-plugin-transform-imports-api) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

    Readme

    babel-plugin-transform-imports-api

    NPM version Build Status Coverage Status

    Convert import default package API to modular reference to reduce package size and transforms member style imports. Inspired by babel-plugin-transform-taroapi and babel-transform-imports.

    example

    import Taro from '@tarojs/taro-h5'
    Taro.request(...)

    This code will become:

    import { request } from '@tarojs/taro-h5'
    request(...)

    and when the configure is:

    // .babelrc
    {
      packagesApis: new Map([
        ['@tarojs/taro-h5', new Set(['request'])],
      ]),
      usePackgesImport: true,
      packagesImport: {
        '@tarojs/taro-h5': {
          transform: (importName, matches) => `@tarojs/taro-h5/lib/${importName.toUpperCase()}`,
          preventFullImport: true,
        },
      }
    }

    this code will become:

    import request from '@tarojs/taro-h5/lib/request';
    request(...)

    Usage

    Step 1: Install

    yarn add --dev babel-plugin-transform-imports-api

    or

    npm install --save-dev babel-plugin-transform-imports-api

    Step 1: Configure .babelrc

    {
      plugins: [
        [require(plugin), {
          packagesApis: new Map([
            ['packageName1', new Set(['api'])],
            ['packageName2', new Set(['api'])],
          ]),
          usePackgesImport: false, // Whether to use packagesImport
          packagesImport: {
            'packageName1': {
              transform: (importName, matches) => `packageName1/lib/${importName.toUpperCase()}`,
              preventFullImport: true,
            },
          }
        }]
      ]
    }