Skip to content
This repository has been archived by the owner on Apr 4, 2022. It is now read-only.

komoot/babel-plugin-transform-require-default

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

babel-plugin-transform-require-default

Why

Babel@6/7 doesn't export default module.exports any more - T2212 Kill CommonJS default export behavior

It means in a ES6 module, you have to use require like:

const A = require('a').default;

How it works

transform:

const A = require('a');

into

function __require_default_func__(module) { return module && module.__esModule ? module["default"] : module; }
const A = __require_default_func__(require('a'));

Options

exclude

string/regexp/function/array, exclude module

{
  plugins: [
    ['transform-require-default', {
      exclude: "lodash",
      exclude: /lodash/,
      exclude: [
        /lodash/,
        "react"
      ],
      exclude(module) {
        return module === 'lodash';
      }
    }]
  ]
}

About

Auto transform require to require default in Babel 6/7

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%