A babel plugin to redirect import modules or specifiers
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]]
}
-
Type:
object
-
Description: A map to describe import redirection.
-
Example:
{ importMap: { 'Foo': 'Bar' } }
-
Type:
object
-
Description: A map to describe import specifier.
-
Example:
{ specifierMap: { Foo: 'Bar', }, }
-
Options:
{ importMap: { 'Foo': 'Bar' } }
-
Example:
import { Component } from 'before'; ↓ ↓ ↓ ↓ ↓ ↓ import { Component } from "after";
-
Options:
{ specifierMap: { Foo: 'Bar', }, }
-
Example:
import { Foo } from 'a-module'; ↓ ↓ ↓ ↓ ↓ ↓ import { Bar } from "a-module";
-
Options:
{ specifierMap: { Foo: { name: 'Foo', targetImport: 'target', }, }, }
-
Example:
import { Foo } from "any-module"; // I don't known `any-module`. ↓ ↓ ↓ ↓ ↓ ↓ import { Foo } from "target";
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";
MIT © ULIVZ