Skip to content

Uses recast to rewrite imports in ES6 modules to use a different path

License

Notifications You must be signed in to change notification settings

rudolfolah/rewrite-imports-es6

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rewrite-imports-es6

A tool that uses recast to rewrite imports in ES6 modules to use a different path.

Rewrites the import to remove the specified import name and replace it with a specified path.

What it does

For example if you are importing a module like this, where the feature import is from a top-level directory:

import {
  AnotherFeature,
  CoolFeature,
  OneMoreFeature,
} from "./features";

console.log(AnotherFeature());
console.log(CoolFeature());
console.log(OneMoreFeature());

You can use this tool to change it to a more specific path like this:

import { AnotherFeature, OneMoreFeature } from "./features";
import CoolFeature from "features/cool_feature/CoolFeature";

console.log(AnotherFeature());
console.log(CoolFeature());
console.log(OneMoreFeature());