代码拉取完成,页面将自动刷新
require a compiled es6 module and handle exports.default.
$ npm i require-esmodule
// foo.js
Object.defineProperty(exports, '__esModule', {value: true})
exports.default = {
foo: 'default-foo'
}
exports.foo = 'foo'
// bar.js
module.exports = {
default: {
bar: 'default-bar'
},
bar: 'bar'
}
// baz.js
module.exports = null
// qux.js
const {
requireModule,
getExports
} = require('require-esmodule')
console.log(requireModule('/path/to/foo').foo) // 'default-foo'
console.log(requireModule('/path/to/foo', false).foo) // 'foo'
console.log(requireModule('/path/to/bar').bar) // 'bar'
// bar.js is not a es6 module
console.log(requireModule('/path/to/baz')) // null
string
ABSOLUTE path of the moduleboolean=true
whether should require export default. Defaults to true
.Returns any
the module exports
requireDefault
as false
const foo = requireModule('./foo', false)
is equivalent to:
import * as foo from './foo'
while
const foo = requireModule('./foo')
is equivalent to:
import foo from './foo'
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
Detect and get the real exports from the return value of require(id)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。