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

babel-plugin-add-import-extension

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-add-import-extension

A babel plugin to add extension on project modules imports

  • 1.3.1
  • npm
  • Socket score

Version published
Weekly downloads
13K
decreased by-21.72%
Maintainers
1
Weekly downloads
 
Created
Source

babel-plugin-add-import-extension

A plugin to add extensions to import and export declarations, is very useful when you use Typescript with Babel and don't want to explicity import or export module with extensions.

How to install:

# using npm
npm install --save-dev babel-plugin-add-import-extension
# usin yarn
yarn add -D babel-plugin-add-import-extension

Add to your plugins on your babel config file:

plugins: ['babel-plugin-add-import-extension'] // defaults to .js extension

Is possible to set the extension when you set the plugin:

plugins: [
    ['babel-plugin-add-import-extension', { extension: 'jsx' }] // will add jsx extension
  ]

You can also replace existing extensions with the one you want

plugins: [
    ['babel-plugin-add-import-extension', { extension: 'jsx', replace: true }] // will add jsx extension
  ]

Let's the transformation begin :)

A module import without extension:

import { add, double } from './lib/numbers'

will be converted to:

import { add, double } from './lib/numbers.js'

A module export without extension:

export { add, double } from './lib/numbers'

will be converted to:

export { add, double } from './lib/numbers.js'

If you add the replace:true option, extensions will be overwritten like so

import { add, double } from './lib/numbers.ts'

will be converted to:

import { add, double } from './lib/numbers.js'

and

export { add, double } from './lib/numbers.ts'

will be converted to:

export { add, double } from './lib/numbers.js'

What this plugin does is to check all imported modules and if your module is not on node_module it will consider that is a project/local module and add the choosed extension, so for node modules it don't add any extension.

I made this plugin for personal use on my typescript boilerplate, but if a lot of people start to use I can better documentation ;)

Keywords

FAQs

Package last updated on 25 Mar 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