mirror of
https://github.com/nuxt/nuxt.git
synced 2025-03-09 03:03:18 +00:00
add -m flag
This commit is contained in:
parent
38f9c21f21
commit
5903319241
@ -5,7 +5,7 @@ process.env.DEBUG = process.env.DEBUG || 'nuxt:*'
|
||||
|
||||
const fs = require('fs')
|
||||
const parseArgs = require('minimist')
|
||||
const { Nuxt, Builder } = require('../')
|
||||
const { Nuxt, Builder, Generator } = require('../')
|
||||
const resolve = require('path').resolve
|
||||
const debug = require('debug')('nuxt:build')
|
||||
debug.color = 2 // Force green color
|
||||
@ -14,10 +14,11 @@ const argv = parseArgs(process.argv.slice(2), {
|
||||
alias: {
|
||||
h: 'help',
|
||||
c: 'config-file',
|
||||
a: 'analyze'
|
||||
a: 'analyze',
|
||||
m: 'mode'
|
||||
},
|
||||
boolean: ['h', 'a'],
|
||||
string: ['c'],
|
||||
string: ['c', 'm'],
|
||||
default: {
|
||||
c: 'nuxt.config.js'
|
||||
}
|
||||
@ -30,9 +31,10 @@ if (argv.help) {
|
||||
Usage
|
||||
$ nuxt build <dir>
|
||||
Options
|
||||
--analyze, -a Launch webpack-bundle-analyzer to optimize your bundles.
|
||||
--config-file, -c Path to Nuxt.js config file (default: nuxt.config.js)
|
||||
--help, -h Displays this message
|
||||
--analyze, -a Launch webpack-bundle-analyzer to optimize your bundles.
|
||||
--mode, -m [spa|universal|static] Nuxt Mode (default: universal)
|
||||
--config-file, -c Path to Nuxt.js config file (default: nuxt.config.js)
|
||||
--help, -h Displays this message
|
||||
`)
|
||||
process.exit(0)
|
||||
}
|
||||
@ -53,6 +55,11 @@ if (typeof options.rootDir !== 'string') {
|
||||
// Create production build when calling `nuxt build`
|
||||
options.dev = false
|
||||
|
||||
// Nuxt Mode
|
||||
if (argv['mode']) {
|
||||
options.mode = argv['mode']
|
||||
}
|
||||
|
||||
// Analyze option
|
||||
options.build = options.build || {}
|
||||
if (argv.analyze) {
|
||||
@ -66,6 +73,15 @@ const builder = new Builder(nuxt)
|
||||
builder.build()
|
||||
.then(() => {
|
||||
debug('Building done')
|
||||
if (options.mode === 'spa') {
|
||||
// Generate on spa mode
|
||||
return new Generator(nuxt, builder).generate({ build: false }).then(() => {
|
||||
if (!nuxt.options.dev) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(`✓ You can now directly upload ${nuxt.options.generate.dir}/ or start server using "nuxt start"`)
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(err) // eslint-disable-line no-console
|
||||
|
19
bin/nuxt-dev
19
bin/nuxt-dev
@ -17,10 +17,11 @@ const argv = parseArgs(process.argv.slice(2), {
|
||||
h: 'help',
|
||||
H: 'hostname',
|
||||
p: 'port',
|
||||
c: 'config-file'
|
||||
c: 'config-file',
|
||||
m: 'mode'
|
||||
},
|
||||
boolean: ['h'],
|
||||
string: ['H', 'c'],
|
||||
string: ['H', 'c', 'm'],
|
||||
default: {
|
||||
c: 'nuxt.config.js'
|
||||
}
|
||||
@ -39,10 +40,11 @@ if (argv.help) {
|
||||
Usage
|
||||
$ nuxt dev <dir> -p <port number> -H <hostname>
|
||||
Options
|
||||
--port, -p A port number on which to start the application
|
||||
--hostname, -H Hostname on which to start the application
|
||||
--config-file, -c Path to Nuxt.js config file (default: nuxt.config.js)
|
||||
--help, -h Displays this message
|
||||
--port, -p A port number on which to start the application
|
||||
--hostname, -H Hostname on which to start the application
|
||||
--mode, -m [spa|universal|static] Nuxt Mode (default: universal)
|
||||
--config-file, -c Path to Nuxt.js config file (default: nuxt.config.js)
|
||||
--help, -h Displays this message
|
||||
`)
|
||||
process.exit(0)
|
||||
}
|
||||
@ -109,5 +111,10 @@ function loadNuxtConfig () {
|
||||
// Force development mode for add hot reloading and watching changes
|
||||
options.dev = true
|
||||
|
||||
// Nuxt Mode
|
||||
if (argv['mode']) {
|
||||
options.mode = argv['mode']
|
||||
}
|
||||
|
||||
return options
|
||||
}
|
||||
|
@ -13,10 +13,11 @@ const resolve = require('path').resolve
|
||||
const argv = parseArgs(process.argv.slice(2), {
|
||||
alias: {
|
||||
h: 'help',
|
||||
c: 'config-file'
|
||||
c: 'config-file',
|
||||
m: 'mode'
|
||||
},
|
||||
boolean: ['h'],
|
||||
string: ['c'],
|
||||
string: ['c', 'm'],
|
||||
default: {
|
||||
c: 'nuxt.config.js'
|
||||
}
|
||||
@ -29,8 +30,9 @@ if (argv.help) {
|
||||
Usage
|
||||
$ nuxt generate <dir>
|
||||
Options
|
||||
--config-file, -c Path to Nuxt.js config file (default: nuxt.config.js)
|
||||
--help, -h Displays this message
|
||||
--mode, -m [spa|universal|static] Nuxt Mode (default: universal)
|
||||
--config-file, -c Path to Nuxt.js config file (default: nuxt.config.js)
|
||||
--help, -h Displays this message
|
||||
`)
|
||||
process.exit(0)
|
||||
}
|
||||
@ -50,6 +52,11 @@ if (typeof options.rootDir !== 'string') {
|
||||
}
|
||||
options.dev = false // Force production mode (no webpack middleware called)
|
||||
|
||||
// Nuxt Mode
|
||||
if (argv['mode']) {
|
||||
options.mode = argv['mode']
|
||||
}
|
||||
|
||||
debug('Generating...')
|
||||
const nuxt = new Nuxt(options)
|
||||
const builder = new Builder(nuxt)
|
||||
|
@ -10,10 +10,11 @@ const argv = parseArgs(process.argv.slice(2), {
|
||||
h: 'help',
|
||||
H: 'hostname',
|
||||
p: 'port',
|
||||
c: 'config-file'
|
||||
c: 'config-file',
|
||||
m: 'mode'
|
||||
},
|
||||
boolean: ['h'],
|
||||
string: ['H', 'c'],
|
||||
string: ['H', 'c', 'm'],
|
||||
default: {
|
||||
c: 'nuxt.config.js'
|
||||
}
|
||||
@ -32,10 +33,11 @@ if (argv.help) {
|
||||
Usage
|
||||
$ nuxt start <dir> -p <port number> -H <hostname>
|
||||
Options
|
||||
--port, -p A port number on which to start the application
|
||||
--hostname, -H Hostname on which to start the application
|
||||
--config-file, -c Path to Nuxt.js config file (default: nuxt.config.js)
|
||||
--help, -h Displays this message
|
||||
--port, -p A port number on which to start the application
|
||||
--hostname, -H Hostname on which to start the application
|
||||
--mode, -m [spa|universal|static] Nuxt Mode (default: universal)
|
||||
--config-file, -c Path to Nuxt.js config file (default: nuxt.config.js)
|
||||
--help, -h Displays this message
|
||||
`)
|
||||
process.exit(0)
|
||||
}
|
||||
@ -59,6 +61,11 @@ if (typeof options.rootDir !== 'string') {
|
||||
// Force production mode (no webpack middleware called)
|
||||
options.dev = false
|
||||
|
||||
// Nuxt Mode
|
||||
if (argv['mode']) {
|
||||
options.mode = argv['mode']
|
||||
}
|
||||
|
||||
// Check if project is built for production
|
||||
const distDir = join(options.rootDir, options.buildDir || '.nuxt', 'dist')
|
||||
if (!fs.existsSync(distDir)) {
|
||||
|
Loading…
Reference in New Issue
Block a user