babel-plugin-redirect-import
v0.2.3
Published
A babel plugin to redirect import modules or specifiers
Downloads
3
Readme
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