0.2.3 • Published 1 year ago

babel-plugin-redirect-import v0.2.3

Weekly downloads
-
License
-
Repository
-
Last release
1 year ago

Table of Contents

Quick Start

Install:

npm i babel-plugin-redirect-import -S  # npm
pnpm i babel-plugin-redirect-import -S # pnpm

Config plugin in .babelrc or babel-loader.

{
  "plugins": [["redirect-import", options]]
}

Options

importMap

  • Type: object
  • Description: A map to describe import redirection.
  • Example:

    {
      importMap: {
        'Foo': 'Bar'
      }
    }

specifierMap

  • Type: object
  • Description: A map to describe import specifier.
  • Example:

    {
      specifierMap: {
        Foo: 'Bar',
      },
    }

Example

Redirect imported module

  • Options:

    {
      importMap: {
        'Foo': 'Bar'
      }
    }
  • Example:

    import { Component } from 'before';
    
          ↓ ↓ ↓ ↓ ↓ ↓
    
    import { Component } from "after";

Redirect imported specifier

  • Options:

    {
      specifierMap: {
        Foo: 'Bar',
      },
    }
  • Example:

    import { Foo } from 'a-module';
    
          ↓ ↓ ↓ ↓ ↓ ↓
    
    import { Bar } from "a-module";

Redirect both import specifier and imported module

  • Options:

    {
      specifierMap: {
        Foo: {
          name: 'Foo',
          targetImport: 'target',
        },
      },
    }
  • Example:

    import { Foo } from "any-module"; // I don't known `any-module`.
    
          ↓ ↓ ↓ ↓ ↓ ↓
    
    import { Foo } from "target";

Redirect unknown imported module

If you want to redirect the imported Module based on the Import Specifier, you can try it:

  • Options:

    `{ 
      importMap: { 
        'before': {
          name: 'after',
          specifierMap: {
            app: 'App',
          },
        },
      } 
    }`; // Plugin Options
  • Example:

    import { app } from "before";
    
          ↓ ↓ ↓ ↓ ↓ ↓
    
    import { App } from "after";

License

MIT © ULIVZ

0.2.3

1 year ago

0.2.2

1 year ago

0.2.1

1 year ago

0.2.0

1 year ago