diff --git a/lib/common/options.js b/lib/common/options.js index 82f1bb4f97..b80681e75b 100755 --- a/lib/common/options.js +++ b/lib/common/options.js @@ -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'), diff --git a/lib/core/nuxt.js b/lib/core/nuxt.js index f25d213c20..8a4dccc511 100644 --- a/lib/core/nuxt.js +++ b/lib/core/nuxt.js @@ -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