From c3bcd0529566dca3b6e05671a4d96368930d5317 Mon Sep 17 00:00:00 2001 From: Pierre RAMBAUD Date: Wed, 15 Mar 2017 15:01:44 +0100 Subject: [PATCH 1/2] Add config file option - Add optional --config-file and -c argv parameters - Display log message if file isn't found Issue: #391 --- bin/nuxt-build | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/bin/nuxt-build b/bin/nuxt-build index 445480b6a2..a1529fa933 100755 --- a/bin/nuxt-build +++ b/bin/nuxt-build @@ -15,13 +15,29 @@ if (process.argv.indexOf('--analyze') !== -1 || process.argv.indexOf('-a') !== - process.argv = without(process.argv, '--analyze', '-a') } +var nuxtConfigFileName = 'nuxt.config.js' +var indexOfConfig = false +if (process.argv.indexOf('--config-file') !== -1) { + indexOfConfig = process.argv.indexOf('--config-file') +} else if (process.argv.indexOf('-c') !== -1) { + indexOfConfig = process.argv.indexOf('-c') +} + +if (indexOfConfig !== false) { + nuxtConfigFileName = process.argv.slice(indexOfConfig)[1] + process.argv = without(process.argv, '--config-file', '-c', nuxtConfigFileName) +} + var rootDir = resolve(process.argv.slice(2)[0] || '.') -var nuxtConfigFile = resolve(rootDir, 'nuxt.config.js') +var nuxtConfigFilePath = resolve(rootDir, nuxtConfigFileName) var options = {} -if (fs.existsSync(nuxtConfigFile)) { - options = require(nuxtConfigFile) +if (fs.existsSync(nuxtConfigFilePath)) { + options = require(nuxtConfigFilePath) +} else { + console.log(`Could not locate ${nuxtConfigFilePath}`) // eslint-disable-line no-console } + if (typeof options.rootDir !== 'string') { options.rootDir = rootDir } From fbd1c609fd3dfe51f564bd380d813b7c6192a6e0 Mon Sep 17 00:00:00 2001 From: Pierre RAMBAUD Date: Wed, 15 Mar 2017 15:14:16 +0100 Subject: [PATCH 2/2] Add missing comments --- bin/nuxt-build | 3 +++ 1 file changed, 3 insertions(+) diff --git a/bin/nuxt-build b/bin/nuxt-build index a1529fa933..50dbc246b8 100755 --- a/bin/nuxt-build +++ b/bin/nuxt-build @@ -16,6 +16,8 @@ if (process.argv.indexOf('--analyze') !== -1 || process.argv.indexOf('-a') !== - } var nuxtConfigFileName = 'nuxt.config.js' + +// --config-file option var indexOfConfig = false if (process.argv.indexOf('--config-file') !== -1) { indexOfConfig = process.argv.indexOf('--config-file') @@ -28,6 +30,7 @@ if (indexOfConfig !== false) { process.argv = without(process.argv, '--config-file', '-c', nuxtConfigFileName) } +// Root directory parameter var rootDir = resolve(process.argv.slice(2)[0] || '.') var nuxtConfigFilePath = resolve(rootDir, nuxtConfigFileName)