cli-build.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*!
  2. * @nuxt/cli v2.15.8 (c) 2016-2021
  3. * Released under the MIT License
  4. * Repository: https://github.com/nuxt/nuxt.js
  5. * Website: https://nuxtjs.org
  6. */
  7. 'use strict';
  8. const consola = require('consola');
  9. const utils = require('@nuxt/utils');
  10. const index = require('./cli-index.js');
  11. require('@nuxt/config');
  12. require('path');
  13. require('exit');
  14. require('chalk');
  15. require('std-env');
  16. require('wrap-ansi');
  17. require('boxen');
  18. require('minimist');
  19. require('hable');
  20. require('defu');
  21. require('semver');
  22. require('fs');
  23. require('execa');
  24. function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
  25. const consola__default = /*#__PURE__*/_interopDefaultLegacy(consola);
  26. const build = {
  27. name: 'build',
  28. description: 'Compiles the application for production deployment',
  29. usage: 'build <dir>',
  30. options: {
  31. ...index.common,
  32. ...index.locking,
  33. analyze: {
  34. alias: 'a',
  35. type: 'boolean',
  36. description: 'Launch webpack-bundle-analyzer to optimize your bundles',
  37. prepare (cmd, options, argv) {
  38. // Analyze option
  39. options.build = options.build || {};
  40. if (argv.analyze && typeof options.build.analyze !== 'object') {
  41. options.build.analyze = true;
  42. }
  43. }
  44. },
  45. devtools: {
  46. type: 'boolean',
  47. default: false,
  48. description: 'Enable Vue devtools',
  49. prepare (cmd, options, argv) {
  50. options.vue = options.vue || {};
  51. options.vue.config = options.vue.config || {};
  52. if (argv.devtools) {
  53. options.vue.config.devtools = true;
  54. }
  55. }
  56. },
  57. generate: {
  58. type: 'boolean',
  59. default: true,
  60. description: 'Don\'t generate static version for SPA mode (useful for nuxt start)'
  61. },
  62. quiet: {
  63. alias: 'q',
  64. type: 'boolean',
  65. description: 'Disable output except for errors',
  66. prepare (cmd, options, argv) {
  67. // Silence output when using --quiet
  68. options.build = options.build || {};
  69. if (argv.quiet) {
  70. options.build.quiet = Boolean(argv.quiet);
  71. }
  72. }
  73. },
  74. standalone: {
  75. type: 'boolean',
  76. default: false,
  77. description: 'Bundle all server dependencies (useful for nuxt-start)',
  78. prepare (cmd, options, argv) {
  79. if (argv.standalone) {
  80. options.build.standalone = true;
  81. }
  82. }
  83. }
  84. },
  85. async run (cmd) {
  86. const config = await cmd.getNuxtConfig({ dev: false, server: false, _build: true });
  87. config.server = (config.mode === utils.MODES.spa || config.ssr === false) && cmd.argv.generate !== false;
  88. const nuxt = await cmd.getNuxt(config);
  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. // TODO: remove if in Nuxt 3
  97. if (nuxt.options.mode === utils.MODES.spa && nuxt.options.target === utils.TARGETS.server && 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. const nextCommand = nuxt.options.target === utils.TARGETS.static ? 'nuxt generate' : 'nuxt start';
  106. consola__default['default'].info('Ready to run `' + (nextCommand) + '`');
  107. }
  108. }
  109. };
  110. exports.default = build;