Skip to content

Transforms default import into namespace import (for libs) and support both namespace and default import for Jest

License

Notifications You must be signed in to change notification settings

bzhangzju/babel-plugin-transform-default-import-hybrid

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

babel-plugin-transform-default-import

Transforms default import into namespace import (for libs).

import apollo from "apollo-server";

transform to

import apollo__DEFAULT__, * as apollo__NAMESPACE__ from "apollo-server";
const apollo = apollo__DEFAULT__ || apollo__NAMESPACE__;

Motivation

Node v. 13.2.0 intorduced support of ES modules, but tools like jest use its own require and use babel for support esm. Native modules import commonjs only with default import, but babel uses named import for libs and it all conflicts. This plugin solves this problem.

Installation

npm i --save-dev babel-plugin-transform-default-import

Usage

Via .babelrc (Recommended)

.babelrc

{
    "plugins": ["transform-default-import", {
        "default": "__DEFAULT__",
        "namespace": "__NAMESPACE__",
        "hybrid": true
    }]
}

Via package.json

{
    "babel": {
        "plugins": ["transform-default-import", {
            "default": "__DEFAULT__",
            "namespace": "__NAMESPACE__",
            "hybrid": true
        }]
    }
}

About

Transforms default import into namespace import (for libs) and support both namespace and default import for Jest

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%