improve modulesDir

This commit is contained in:
Pooya Parsa 2017-12-13 04:39:38 +03:30
parent 6fc57895b5
commit 49b43c4be3
2 changed files with 8 additions and 24 deletions

View File

@ -49,19 +49,11 @@ Options.from = function (_options) {
options.buildDir = resolve(options.rootDir, options.buildDir)
options.cacheDir = resolve(options.rootDir, options.cacheDir)
// Normalize modulesDir
/* istanbul ignore if */
if (!options.modulesDir) {
options.modulesDir = ['node_modules']
}
if (!Array.isArray(options.modulesDir)) {
options.modulesDir = [options.modulesDir]
}
options.modulesDir = options.modulesDir.filter(dir => hasValue(dir)).map(dir => resolve(options.rootDir, dir))
// Always add nuxt to modulesDir array
const nuxtModulesDir = join(options.nuxtDir, 'node_modules')
options.modulesDir.push(nuxtModulesDir)
// Populate modulesDir
options.modulesDir = []
.concat(options.modulesDir, join(options.nuxtDir, 'node_modules'))
.filter(dir => hasValue(dir))
.map(dir => resolve(options.rootDir, dir))
// If app.html is defined, set the template path to the user template
options.appTemplatePath = resolve(options.buildDir, 'views/app.template.html')
@ -209,6 +201,7 @@ Options.defaults = {
cacheDir: '.cache',
nuxtDir: resolve(__dirname, '../..'),
nuxtAppDir: resolve(__dirname, '../app'),
modulesDir: ['node_modules'], // ~> relative to options.rootDir
build: {
analyze: false,
profile: process.argv.includes('--profile'),

View File

@ -17,18 +17,9 @@ module.exports = class Nuxt {
constructor(options = {}) {
this.options = Options.from(options)
// Paths for resolving requires from `rootDir`
this.nodeModulePaths = Module._nodeModulePaths(this.options.rootDir)
if (this.options.nuxtDir.indexOf(this.options.rootDir) !== 0) {
this.nodeModulePaths = [
...this.nodeModulePaths,
...Module._nodeModulePaths(this.options.nuxtDir)
]
}
this.initialized = false
this.errorHandler = this.errorHandler.bind(this)
// Hooks
this._hooks = {}
this.hook = this.hook.bind(this)
@ -178,7 +169,7 @@ module.exports = class Nuxt {
resolvePath(path) {
// Try to resolve using NPM resolve path first
try {
let resolvedPath = Module._resolveFilename(path, { paths: this.nodeModulePaths })
let resolvedPath = Module._resolveFilename(path, { paths: this.options.modulesDir })
return resolvedPath
} catch (e) {
// Just continue