mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-30 09:27:13 +00:00
fix(core): use options.extensions for resolvePath
This commit is contained in:
parent
811201925d
commit
f30ef38c70
@ -3,9 +3,10 @@ const enableDestroy = require('server-destroy')
|
||||
const Module = require('module')
|
||||
const { isPlainObject } = require('lodash')
|
||||
const chalk = require('chalk')
|
||||
const { existsSync } = require('fs-extra')
|
||||
const { Options } = require('../common')
|
||||
const { sequence, printError, printWarn } = require('../common/utils')
|
||||
const { join, resolve } = require('path')
|
||||
const { resolve } = require('path')
|
||||
const { version } = require('../../package.json')
|
||||
const ModuleContainer = require('./module')
|
||||
const Renderer = require('./renderer')
|
||||
@ -182,22 +183,30 @@ module.exports = class Nuxt {
|
||||
resolvePath(path) {
|
||||
// Try to resolve using NPM resolve path first
|
||||
try {
|
||||
let resolvedPath = Module._resolveFilename(path, {
|
||||
const resolvedPath = Module._resolveFilename(path, {
|
||||
paths: this.options.modulesDir
|
||||
})
|
||||
return resolvedPath
|
||||
} catch (e) {
|
||||
} catch (error) {
|
||||
if (error.code === 'MODULE_NOT_FOUND') {
|
||||
// Continue to try other methods
|
||||
} else {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
// Shorthand to resolve from project dirs
|
||||
let _path = path
|
||||
if (path.indexOf('@@') === 0 || path.indexOf('~~') === 0) {
|
||||
return join(this.options.rootDir, path.substr(2))
|
||||
_path = resolve(this.options.rootDir, path.substr(2))
|
||||
} else if (path.indexOf('@') === 0 || path.indexOf('~') === 0) {
|
||||
return join(this.options.srcDir, path.substr(1))
|
||||
_path = resolve(this.options.srcDir, path.substr(1))
|
||||
}
|
||||
|
||||
return resolve(this.options.srcDir, path)
|
||||
for (let ext of [''].concat(this.options.extensions)) {
|
||||
if (existsSync(_path + ext)) {
|
||||
return _path + ext
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async close(callback) {
|
||||
|
Loading…
Reference in New Issue
Block a user