Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

babel-plugin-resolver

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-resolver

Resolve modules from any directory.

  • 1.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
678
increased by121.57%
Maintainers
1
Weekly downloads
 
Created
Source

Babel Resolver Plugin NPM version Build status

Resolve modules from any directory.

import User from '../../models/User';

Becomes:

import User from 'models/User';

Usage

npm i babel-plugin-resolver --save
rm -rf ~/.babel.json

In .babelrc:

{
  "presets": ["es2015"],
  "plugins": [["resolver", {"resolveDirs": ["src"]}]]
}

Given the directory structure:

/app
  .babelrc
  /src
    /models
      User.js
    /controllers
      User.js

In app/controllers/User.js:

import UserModel from 'models/User';
// => resolves: "app/src/models/User.js"

This example uses Babel 6.

Note: Run rm -rf ~/.babel.json if you're seeing errors.

Note2: This plugin is only called when you use import, not require.

Resolving Multiple Directories

In .babelrc:

{
  "presets": ["es2015"],
  "plugins": [["resolver", {"resolveDirs": ["src", "src/lib"]}]]
}

Given the directory structure:

/app
  .babelrc
  /src
    /models
      User.js
    /controllers
      User.js
    /lib
      utils.js

In app/controllers/User.js:

import UserModel from 'models/User';
// => resolves: "app/src/models/User.js"
import utils from 'utils';
// => resolves: "app/src/lib/utils.js"

Installation

npm i babel-plugin-resolver --save
rm -f ~/.babel.json

Why not just set NODE_PATH?

While setting NODE_PATH=app is a perfectly valid solution, babel-resolver is more explicit and lets you avoid mucking around with environment variables.

License

MIT

Keywords

FAQs

Package last updated on 13 Sep 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc