116 lines
3.3 KiB
JavaScript
116 lines
3.3 KiB
JavaScript
/*!
|
|
* @nuxt/cli v2.13.3 (c) 2016-2020
|
|
|
|
* - All the amazing contributors
|
|
* Released under the MIT License.
|
|
* Website: https://nuxtjs.org
|
|
*/
|
|
'use strict';
|
|
|
|
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
|
|
|
const index = require('./cli-index.js');
|
|
require('path');
|
|
require('@nuxt/config');
|
|
require('exit');
|
|
const utils = require('@nuxt/utils');
|
|
require('chalk');
|
|
require('std-env');
|
|
require('wrap-ansi');
|
|
require('boxen');
|
|
const consola = _interopDefault(require('consola'));
|
|
require('minimist');
|
|
require('hable');
|
|
require('fs');
|
|
require('execa');
|
|
|
|
const build = {
|
|
name: 'build',
|
|
description: 'Compiles the application for production deployment',
|
|
usage: 'build <dir>',
|
|
options: {
|
|
...index.common,
|
|
...index.locking,
|
|
analyze: {
|
|
alias: 'a',
|
|
type: 'boolean',
|
|
description: 'Launch webpack-bundle-analyzer to optimize your bundles',
|
|
prepare (cmd, options, argv) {
|
|
// Analyze option
|
|
options.build = options.build || {};
|
|
if (argv.analyze && typeof options.build.analyze !== 'object') {
|
|
options.build.analyze = true;
|
|
}
|
|
}
|
|
},
|
|
devtools: {
|
|
type: 'boolean',
|
|
default: false,
|
|
description: 'Enable Vue devtools',
|
|
prepare (cmd, options, argv) {
|
|
options.vue = options.vue || {};
|
|
options.vue.config = options.vue.config || {};
|
|
if (argv.devtools) {
|
|
options.vue.config.devtools = true;
|
|
}
|
|
}
|
|
},
|
|
generate: {
|
|
type: 'boolean',
|
|
default: true,
|
|
description: 'Don\'t generate static version for SPA mode (useful for nuxt start)'
|
|
},
|
|
quiet: {
|
|
alias: 'q',
|
|
type: 'boolean',
|
|
description: 'Disable output except for errors',
|
|
prepare (cmd, options, argv) {
|
|
// Silence output when using --quiet
|
|
options.build = options.build || {};
|
|
if (argv.quiet) {
|
|
options.build.quiet = Boolean(argv.quiet);
|
|
}
|
|
}
|
|
},
|
|
standalone: {
|
|
type: 'boolean',
|
|
default: false,
|
|
description: 'Bundle all server dependencies (useful for nuxt-start)',
|
|
prepare (cmd, options, argv) {
|
|
if (argv.standalone) {
|
|
options.build.standalone = true;
|
|
}
|
|
}
|
|
}
|
|
},
|
|
async run (cmd) {
|
|
const config = await cmd.getNuxtConfig({ dev: false, server: false, _build: true });
|
|
config.server = (config.mode === utils.MODES.spa || config.ssr === false) && cmd.argv.generate !== false;
|
|
const nuxt = await cmd.getNuxt(config);
|
|
|
|
if (cmd.argv.lock) {
|
|
await cmd.setLock(await index.createLock({
|
|
id: 'build',
|
|
dir: nuxt.options.buildDir,
|
|
root: config.rootDir
|
|
}));
|
|
}
|
|
|
|
// TODO: remove if in Nuxt 3
|
|
if (nuxt.options.mode === utils.MODES.spa && nuxt.options.target === utils.TARGETS.server && cmd.argv.generate !== false) {
|
|
// Build + Generate for static deployment
|
|
const generator = await cmd.getGenerator(nuxt);
|
|
await generator.generate({ build: true });
|
|
} else {
|
|
// Build only
|
|
const builder = await cmd.getBuilder(nuxt);
|
|
await builder.build();
|
|
|
|
const nextCommand = nuxt.options.target === utils.TARGETS.static ? 'nuxt export' : 'nuxt start';
|
|
consola.info('Ready to run `' + (nextCommand) + '`');
|
|
}
|
|
}
|
|
};
|
|
|
|
exports.default = build;
|