require-esmodule
require a compiled es6 module and handle exports.default.
Install
$ npm i require-esmodule
Usage
// foo.jsObject exportsdefault = foo: 'default-foo' exportsfoo = 'foo'
// bar.jsmoduleexports = default: bar: 'default-bar' bar: 'bar'
// baz.jsmoduleexports = null
// qux.jsconst requireModule getExports } = console // 'default-foo' console // 'foo' console // 'bar'// bar.js is not a es6 module console // null
requireModule(id: string, requireDefault? : boolean = true)
- id
string
ABSOLUTE path of the module - requireDefault?
boolean=true
whether should require export default. Defaults totrue
.
Returns any
the module exports
requireDefault
as false
const foo =
is equivalent to:
while
const foo =
is equivalent to:
The purpose of require-esmodule
is to detect and make it easier to get the default exports of es modules, so the default value of requireDefault
is set to true
getExports(exports: any, requireDefault?)
Detect and get the real exports from the return value of require(id)