mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-11 08:33:53 +00:00
improve modulesDir
This commit is contained in:
parent
6fc57895b5
commit
49b43c4be3
@ -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'),
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user