mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-30 17:37:14 +00:00
ad0649925d
Extracted common logic Improved style consistency
44 lines
1.1 KiB
JavaScript
44 lines
1.1 KiB
JavaScript
const { Utils } = require('../..')
|
|
const { resolve } = require('path')
|
|
const { existsSync } = require('fs')
|
|
|
|
const getRootDir = argv => resolve(argv._[0] || '.')
|
|
const getNuxtConfigFile = argv => resolve(getRootDir(argv), argv['config-file'])
|
|
|
|
exports.nuxtConfigFile = getNuxtConfigFile
|
|
|
|
exports.loadNuxtConfig = argv => {
|
|
const rootDir = getRootDir(argv)
|
|
const nuxtConfigFile = getNuxtConfigFile(argv)
|
|
|
|
let options = {}
|
|
|
|
if (existsSync(nuxtConfigFile)) {
|
|
delete require.cache[nuxtConfigFile]
|
|
options = require(nuxtConfigFile)
|
|
} else if (argv['config-file'] !== 'nuxt.config.js') {
|
|
Utils.fatalError('Could not load config file: ' + argv['config-file'])
|
|
}
|
|
|
|
if (typeof options.rootDir !== 'string') {
|
|
options.rootDir = rootDir
|
|
}
|
|
|
|
// Nuxt Mode
|
|
options.mode =
|
|
(argv['spa'] && 'spa') || (argv['universal'] && 'universal') || options.mode
|
|
|
|
return options
|
|
}
|
|
|
|
exports.getLatestHost = argv => {
|
|
const port =
|
|
argv.port || process.env.PORT || process.env.npm_package_config_nuxt_port
|
|
const host =
|
|
argv.hostname ||
|
|
process.env.HOST ||
|
|
process.env.npm_package_config_nuxt_host
|
|
|
|
return { port, host }
|
|
}
|