diff --git a/lib/builder/webpack/base.config.js b/lib/builder/webpack/base.config.js index 987e32acb7..5188e92063 100644 --- a/lib/builder/webpack/base.config.js +++ b/lib/builder/webpack/base.config.js @@ -48,13 +48,13 @@ export default function webpackBaseConfig(name) { 'static': join(this.options.srcDir, 'static') }, modules: [ - this.options.modulesDir, + ...this.options.modulesDir, nodeModulesDir ] }, resolveLoader: { modules: [ - this.options.modulesDir, + ...this.options.modulesDir, nodeModulesDir ] }, diff --git a/lib/builder/webpack/server.config.js b/lib/builder/webpack/server.config.js index 47a74cd3cb..5a923d6390 100644 --- a/lib/builder/webpack/server.config.js +++ b/lib/builder/webpack/server.config.js @@ -53,7 +53,7 @@ export default function webpackServerConfig() { // https://webpack.js.org/configuration/externals/#externals // https://github.com/liady/webpack-node-externals const moduleDirs = [ - this.options.modulesDir + ...this.options.modulesDir // Temporary disabled due to vue-server-renderer module search limitations // resolve(__dirname, '..', 'node_modules') ] diff --git a/lib/common/options.js b/lib/common/options.js index 951a245f91..39c8e3b12c 100755 --- a/lib/common/options.js +++ b/lib/common/options.js @@ -39,10 +39,20 @@ Options.from = function (_options) { const hasValue = v => typeof v === 'string' && v options.rootDir = hasValue(options.rootDir) ? options.rootDir : process.cwd() options.srcDir = hasValue(options.srcDir) ? resolve(options.rootDir, options.srcDir) : options.rootDir - options.modulesDir = resolve(options.rootDir, hasValue(options.modulesDir) ? options.modulesDir : 'node_modules') options.buildDir = resolve(options.rootDir, options.buildDir) options.cacheDir = resolve(options.rootDir, options.cacheDir) + if (Array.isArray(options.modulesDir) && options.modulesDir.length) { + options.modulesDir = options.modulesDir.reduce((modules, dir) => { + if (hasValue(dir)) { + modules.push(resolve(options.rootDir, dir)) + } + return modules + }, []) + } else { + options.modulesDir = [resolve(options.rootDir, hasValue(options.modulesDir) ? options.modulesDir : 'node_modules')] + } + // If app.html is defined, set the template path to the user template options.appTemplatePath = resolve(options.buildDir, 'views/app.template.html') if (existsSync(join(options.srcDir, 'app.html'))) { @@ -126,7 +136,7 @@ Options.from = function (_options) { path: [ options.srcDir, options.rootDir, - options.modulesDir + ...options.modulesDir ] }, // https://github.com/postcss/postcss-url diff --git a/test/fixtures/basic/nuxt.config.js b/test/fixtures/basic/nuxt.config.js index 6d0b354c14..369382e815 100644 --- a/test/fixtures/basic/nuxt.config.js +++ b/test/fixtures/basic/nuxt.config.js @@ -1,3 +1,5 @@ +const path = require('path') + module.exports = { generate: { routes: [ @@ -8,6 +10,7 @@ module.exports = { interval: 200, subFolders: true }, + modulesDir: path.join(__dirname, '..', '..', '..', 'node_modules'), hooks: { ready(nuxt) { nuxt.__hook_called__ = true diff --git a/test/fixtures/with-config/nuxt.config.js b/test/fixtures/with-config/nuxt.config.js index 8acd8c068f..bd564d5e8a 100644 --- a/test/fixtures/with-config/nuxt.config.js +++ b/test/fixtures/with-config/nuxt.config.js @@ -16,7 +16,9 @@ module.exports = { ] } }, - modulesDir: path.join(__dirname, '..', '..', '..', 'node_modules'), + modulesDir: [ + path.join(__dirname, '..', '..', '..', 'node_modules') + ], transition: 'test', layoutTransition: 'test', loadingIndicator: 'circle',