UNPKG

2.9 kBJavaScriptView Raw
1/*!
2 * @nuxt/cli v2.12.0 (c) 2016-2020
3
4 * - All the amazing contributors
5 * Released under the MIT License.
6 * Website: https://nuxtjs.org
7*/
8'use strict';
9
10const index = require('./cli-index.js');
11require('path');
12require('@nuxt/config');
13require('exit');
14require('@nuxt/utils');
15require('chalk');
16require('std-env');
17require('wrap-ansi');
18require('boxen');
19require('consola');
20require('minimist');
21require('hable');
22require('fs');
23require('execa');
24
25const build = {
26 name: 'build',
27 description: 'Compiles the application for production deployment',
28 usage: 'build <dir>',
29 options: {
30 ...index.common,
31 ...index.locking,
32 analyze: {
33 alias: 'a',
34 type: 'boolean',
35 description: 'Launch webpack-bundle-analyzer to optimize your bundles',
36 prepare (cmd, options, argv) {
37 // Analyze option
38 options.build = options.build || {};
39 if (argv.analyze && typeof options.build.analyze !== 'object') {
40 options.build.analyze = true;
41 }
42 }
43 },
44 devtools: {
45 type: 'boolean',
46 default: false,
47 description: 'Enable Vue devtools',
48 prepare (cmd, options, argv) {
49 options.vue = options.vue || {};
50 options.vue.config = options.vue.config || {};
51 if (argv.devtools) {
52 options.vue.config.devtools = true;
53 }
54 }
55 },
56 generate: {
57 type: 'boolean',
58 default: true,
59 description: 'Don\'t generate static version for SPA mode (useful for nuxt start)'
60 },
61 quiet: {
62 alias: 'q',
63 type: 'boolean',
64 description: 'Disable output except for errors',
65 prepare (cmd, options, argv) {
66 // Silence output when using --quiet
67 options.build = options.build || {};
68 if (argv.quiet) {
69 options.build.quiet = Boolean(argv.quiet);
70 }
71 }
72 },
73 standalone: {
74 type: 'boolean',
75 default: false,
76 description: 'Bundle all server dependencies (useful for nuxt-start)',
77 prepare (cmd, options, argv) {
78 if (argv.standalone) {
79 options.build.standalone = true;
80 }
81 }
82 }
83 },
84 async run (cmd) {
85 const config = await cmd.getNuxtConfig({ dev: false, server: false, _build: true });
86 config.server = config.mode === 'spa' && cmd.argv.generate !== false;
87 const nuxt = await cmd.getNuxt(config);
88
89 if (cmd.argv.lock) {
90 await cmd.setLock(await index.createLock({
91 id: 'build',
92 dir: nuxt.options.buildDir,
93 root: config.rootDir
94 }));
95 }
96
97 if (nuxt.options.mode === 'spa' && cmd.argv.generate !== false) {
98 // Build + Generate for static deployment
99 const generator = await cmd.getGenerator(nuxt);
100 await generator.generate({ build: true });
101 } else {
102 // Build only
103 const builder = await cmd.getBuilder(nuxt);
104 await builder.build();
105 }
106 }
107};
108
109exports.default = build;