0.0.2 • Published 6 years ago

@mrjs/babel-plugin-sresolver v0.0.2

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

babel-plugin-sresolver

Maintenance Status NPM version Build Status Linux Build Status Windows Coverage Status

A Babel plugin to add a new resolver for your modules when compiling your code using Babel.

Description

Default Node only load modules from node_modules folder. This plugin can autoload all package.json files recursively, so you can named your library to require/import every where from your workspace. For example, instead of using complex relative paths like ../../../../utils/my-utils you can place use @utils/my-utils. It will allow you to work faster since you won't need to calculate how many levels of directory you have to go up before accessing the file.

{
    "name": "@utils",
    "main": "./"
}
// Use this:
import MyUtilFn from '@utils/MyUtilFn';
// Instead of that:
import MyUtilFn from '../../../../utils/MyUtilFn';

// And it also work with require calls
// Use this:
const MyUtilFn = require('@utils/MyUtilFn');
// Instead of that:
const MyUtilFn = require('../../../../utils/MyUtilFn');

Getting started

Install the plugin

$ npm install --save-dev @mrjs/babel-plugin-sresolver

Specify the plugin in your .babelrc .Here's an example:

{
  "plugins": [
    ["@mrjs/babel-plugin-sresolver"]
  ]
}

or custom root folder for scan package.json

{
  "plugins": [
    ["@mrjs/babel-plugin-sresolver", {
      "root": ["./src"],
    }]
  ]
}

License

MIT, see LICENSE.md for details.

Are you also using it? Send a PR!

0.0.2

6 years ago

0.0.1

6 years ago