convert-relative-to-alias-imports

0.0.2 • Public • Published

Convert relative to alias imports

Simple utility to convert relative to aliased imports.

Usage

npx convert-relative-to-alias-imports <alias> <rootDirectory>;

or use command line flags:

  • alias (or a)
  • rootDir (or r)

Example

Given a project in which the code is in the ./src directory.

Add the following to your tsconfig.json:

{
    "compilerOptions":{
        "baseUrl": "src",
        "paths": {
          "@/*": ["./*"],
        }
    }
}

Then run the following command to update all import statements in your project: npx convert-relative-to-alias-imports @ src;

Your imports will now look like this:

import example from '@/utils/example';

Instead of:

import example from '../utils/example';

Your tests might complain about this setup. Possible solution is to add this to your jest config:

{
    moduleNameMapper: {
        '@/(.*)': '<rootDir>/src/$1',
    },
}

Dependents (0)

Package Sidebar

Install

npm i convert-relative-to-alias-imports

Weekly Downloads

0

Version

0.0.2

License

MIT

Unpacked Size

5.86 kB

Total Files

6

Last publish

Collaborators

  • frtelg