New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

babel-plugin-module-extension-resolver

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-module-extension-resolver

Babel plugin that resolves and maps module extensions.

  • 0.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.2K
decreased by-14.46%
Maintainers
1
Weekly downloads
 
Created
Source

babel-plugin-module-extension-resolver

Build Status (Windows) Build Status (macOS) Build Status (Linux) Syntax check Release Node.js version License

Babel plugin that resolves and maps module extensions.

Inspired by babel-plugin-extension-resolver.

Examples

JavaScript

Directory structure:

root
├ dir
│ ├ index.js
│ └ lib.js
├ main.js
└ settings.json

Input (main.js):

require("./dir/lib");
require("./dir/lib.js");    // file exists
require("./dir");           // directory has "index.js"
require("./settings");      // ".json" extension
require("./no-such-file");  // file NOT exists
require("dir");             // not begins with "."

Output:

require("./dir/lib.js");
require("./dir/lib.js");
require("./dir/index.js");
require("./settings.json");
require("./no-such-file");
require("dir");

JavaScript (.mjs extension)

Directory structure:

root
├ dir
│ ├ index.mjs
│ └ lib.mjs
└ main.mjs

Input (main.mjs):

import "./dir/lib";
import "./dir";

Output:

import "./dir/lib.mjs";
import "./dir/index.mjs";

TypeScript

Directory structure:

root
├ dir
│ ├ index.ts
│ └ lib.ts
└ main.ts

Input (main.ts):

import "./dir/lib";
import "./dir";

Output:

import "./dir/lib.js";
import "./dir/index.js";

NOTE: .ts is replaced with .js. This behavior can be customized by options.

For complete project, see below examples.

Install

npm i -D babel-plugin-module-extension-resolver

.babelrc

{
  "plugins": ["module-extension-resolver"]
}

With options:

{
  "plugins": [
    ["module-extension-resolver", {
      "extensions": [".js", ".cjs", ".mjs", ".es", ".es6", ".ts", ".node", ".json"],
      "map": {
        ".ts": ".js",
        ".es": ".js",
        ".es6": ".js",
        ".node": ".js"
      }
    }]
  ]
}

Options

extensions

extensions to resolve

defaults:

[
  ".js",
  ".cjs",
  ".mjs",
  ".es",
  ".es6",
  ".ts",
  ".node",
  ".json"
]

map

extension mapper

defaults:

{
  ".ts": ".js",
  ".es": ".js",
  ".es6": ".js",
  ".node": ".js"
}

Changelog

See CHANGELOG.md.

Keywords

FAQs

Package last updated on 04 Jan 2020

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