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

babel-resolver

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-resolver

Resolve modules from any directory.

  • 0.0.6
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.8K
increased by41.79%
Maintainers
1
Weekly downloads
 
Created
Source

Babel Resolver NPM version Build status Coverage status

Resolve modules from any directory.

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

Becomes:

import User from 'models/User';

Usage

Using Babel 6 & babel-core/register:

var resolve = require('path').resolve;
var localModulesDir = resolve(__dirname, 'app');
var anotherDirToCheck = resolve(__dirname, 'app/lib');
var resolver = require('babel-resolver')(localModulesDir, anotherDirToCheck);

require('babel-core/register')({
  presets: ['es2015'], // required for 'import'
  resolveModuleSource: resolver
});
require('./app');

Note: Run rm -rf ~/.babel.json before use to clear babel's cache. If you're seeing errors, try this again.

Note2: Babel's resolveModuleSource is currently only called when you use import 'module', not when use require('module')

Also, keep in mind that you must provide absolute directory paths to babel-resolver.

Installation

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

Why not just set NODE_PATH?

Setting NODE_PATH=app is a perfectly valid solution. babel-resolver is for those who:

  • find environment variables annoying
  • want to resolve modules from more than one directory

License

MIT

Keywords

FAQs

Package last updated on 11 Nov 2015

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