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.17
  • 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

In app/index.js:

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

require('./app');

In app/app.js:

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

This example uses Babel 6 and babel-core/register.

If you wish to define options in .babelrc, use the Babel Resolver Plugin instead.

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

Note2: Babel's resolveModuleSource is only called when you use import, not require.

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

Resolving Multiple Directories

In app/index.js:

var path = require('path');
var localModulesDir = __dirname;
var anotherDirToCheck = path.resolve(__dirname, 'lib');

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

In app/app.js:

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

import somethingInLib from 'somethingInLib';
// => resolves: "app/lib/somethingInLib.js"

Installation

npm i babel-resolver --save
rm -rf ~/.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 04 Jan 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