Skip to content

classflow/import-alias

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

import-alias

Import by alias and forget about maintaining relative paths.

import-alias allows you to add nicknames to files that you can use in import statements. This means you can forget about figuring out long relative directories and, even better, you can rearrange files and have the import statements rewritten automatically.

import-alias

Installation

TODO: publish npm module

npm i -g import-alias

Until the npm package is published, install the source and link.

git clone [email protected]:classflow/import-alias.git
cd import-alias
npm i
npm link

Usage

Defining

Define unique aliases by adding @alias comments to files. Most characters are supported.

// @alias Widget
// @alias forms/Slim
// @alias services/ajax
// @alias foo-mister_crazy123!!+

Importing

Import aliased files with @{alias}.

import Widget from '@Widget';
import Slim from '@forms/Slim';
import * as ajax from '@services/ajax';
import crazy from '@foo-mister_crazy123!!+';

Transforming

CLI

Transform the import statements at any time by running import-alias in the root directory. The alias will be replaced with a relative path and a marker appended to the line for future transformations.

import-alias

rewritten source

import Widget from './shared/components/Widget'; // @Widget
import Slim from './shared/components/forms/Slim'; // @forms/Slim
import * as ajax from '../services/transport/ajax'; // @services/ajax
import crazy from '../crazy/nicknamed/module'; // @foo-mister_crazy123!!+

As a Module

You can also use import-alias from other code.

import { transform, ignore } from 'import-alias';
ignore(['libraries', 'min', 'build']);
transform('path/to/source').then(() => {
    console.log('Life is easy.');
});

Notes

The current version finds all js, jsx, and es6 files recursively and ignores the directories node_modules, .git, lib, frameworks, and bower_components. These options will be made configurable in a future version. View the [change log] changelog for details.


kickstarted by npm-boom

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published