New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

babel-plugin-module-resolve

Package Overview
Dependencies
Maintainers
1
Versions
54
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-module-resolve

Module resolver plugin for Babel

latest
Source
npmnpm
Version
1.7.0
Version published
Weekly downloads
267
-30.1%
Maintainers
1
Weekly downloads
 
Created
Source

babel-plugin-module-resolve

A Babel plugin to import similar to webpack alias.
Implemented based on plugin enhanced-resolve.

Example

Simplify the require import System.import System.import path.

// simple @utils -> <root dir>/utils
import t from '@utils';
// instead
import t from '../../utils/index';

const t = require('@utils');
// instead
const t = require('../../utils/index');

Usage

Install the plugin

npm install --save-dev babel-plugin-module-resolve`

or

yarn add --dev babel-plugin-module-resolve`

Specify the plugin in your .babelrc with the custom root or alias. Here's an example:

{
  "plugins": [
    [
      "module-resolve",
      {
        "roots": ["./src"],
        "alias": {
          "@/*": ["./*"],
          "assets": ["./assets"]
        }
      }
    ]
  ]
}

Also supports the use of paths configuration in jsconfig and tsconfig.

{
  "compilerOptions": {
    "baseUrl": "src",
    "paths": {
      "@/*": ["./*"]
    }
  }
}

Options

Detailed reference enhanced-resolve.

roots

Parsed root directory

  • Type: array
  • Default: cwd | compilerOptions.baseUrl

alias

Alias configuration

  • Type: object
  • Default: { @: resolve('src') } | compilerOptions.paths

extensions

Parse file types

  • Type: array
  • Default: ['.js', '.jsx', '.es', '.es6', '.mjs', '.ts', '.tsx']

FAQs

Package last updated on 09 Dec 2023

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