1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | 'use strict';
|
9 |
|
10 | const index = require('./cli-index.js');
|
11 | require('path');
|
12 | require('@nuxt/config');
|
13 | require('exit');
|
14 | require('@nuxt/utils');
|
15 | require('chalk');
|
16 | require('std-env');
|
17 | require('wrap-ansi');
|
18 | require('boxen');
|
19 | require('consola');
|
20 | require('minimist');
|
21 | require('hable');
|
22 | require('fs');
|
23 | require('execa');
|
24 |
|
25 | const 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 |
|
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 |
|
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 |
|
99 | const generator = await cmd.getGenerator(nuxt);
|
100 | await generator.generate({ build: true });
|
101 | } else {
|
102 |
|
103 | const builder = await cmd.getBuilder(nuxt);
|
104 | await builder.build();
|
105 | }
|
106 | }
|
107 | };
|
108 |
|
109 | exports.default = build;
|