babel-plugin-redirect-import
TypeScript icon, indicating that this package has built-in type declarations

0.2.3 • Public • Published

babel-plugin-redirect-import

A babel plugin to redirect import modules or specifiers

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

Readme

Keywords

none

Package Sidebar

Install

npm i babel-plugin-redirect-import

Weekly Downloads

2

Version

0.2.3

License

none

Unpacked Size

12.8 kB

Total Files

7

Last publish

Collaborators

  • ulivz