mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-27 16:12:12 +00:00
fix: passing module as a function
This commit is contained in:
parent
4028abc1e1
commit
6e44648bfc
@ -85,28 +85,27 @@ class Module {
|
||||
// Allows passing runtime options to each module
|
||||
const options = moduleOpts.options || {}
|
||||
const originalSrc = moduleOpts.src || moduleOpts
|
||||
let src = originalSrc
|
||||
// Resolve module
|
||||
let module
|
||||
let module = originalSrc
|
||||
try {
|
||||
if (typeof src === 'string') {
|
||||
if (typeof module === 'string') {
|
||||
// Using ~ or ./ shorthand modules are resolved from project srcDir
|
||||
if (src.indexOf('~') === 0 || src.indexOf('./') === 0) {
|
||||
src = path.join(this.options.srcDir, src.substr(1))
|
||||
if (module.indexOf('~') === 0 || module.indexOf('./') === 0) {
|
||||
module = path.join(this.options.srcDir, module.substr(1))
|
||||
}
|
||||
// eslint-disable-next-line no-eval
|
||||
module = eval('require')(src)
|
||||
module = eval('require')(module)
|
||||
}
|
||||
} catch (e) /* istanbul ignore next */ {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error('[nuxt] Unable to resolve module', src)
|
||||
console.error('[nuxt] Unable to resolve module', module)
|
||||
// eslint-disable-next-line no-console
|
||||
console.error(e)
|
||||
process.exit(0)
|
||||
}
|
||||
// Validate module
|
||||
/* istanbul ignore if */
|
||||
if (!(module instanceof Function)) {
|
||||
if (typeof module !== 'function') {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error(`[nuxt] Module [${originalSrc}] should export a function`)
|
||||
process.exit(1)
|
||||
|
Loading…
Reference in New Issue
Block a user