vite 5.2.7 → 6.0.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/node/cli.js CHANGED
@@ -2,7 +2,7 @@ import path from 'node:path';
2
2
  import fs from 'node:fs';
3
3
  import { performance } from 'node:perf_hooks';
4
4
  import { EventEmitter } from 'events';
5
- import { A as colors, v as createLogger, r as resolveConfig } from './chunks/dep-C-KAszbv.js';
5
+ import { E as colors, x as createLogger, r as resolveConfig, F as Environment } from './chunks/dep-hQh5_mg-.js';
6
6
  import { VERSION } from './constants.js';
7
7
  import 'node:fs/promises';
8
8
  import 'node:url';
@@ -26,20 +26,20 @@ import 'child_process';
26
26
  import 'node:os';
27
27
  import 'node:crypto';
28
28
  import 'node:dns';
29
- import 'crypto';
30
- import 'module';
31
29
  import 'node:assert';
32
30
  import 'node:v8';
31
+ import 'module';
33
32
  import 'node:worker_threads';
34
- import 'node:buffer';
35
- import 'node:events';
36
33
  import 'rollup/parseAst';
37
- import 'querystring';
34
+ import 'node:events';
35
+ import 'crypto';
36
+ import 'node:buffer';
38
37
  import 'node:readline';
39
38
  import 'zlib';
40
39
  import 'buffer';
41
40
  import 'https';
42
41
  import 'tls';
42
+ import 'querystring';
43
43
  import 'node:zlib';
44
44
 
45
45
  function toArr(any) {
@@ -687,7 +687,7 @@ const filterDuplicateOptions = (options) => {
687
687
  /**
688
688
  * removing global flags before passing as command specific sub-configs
689
689
  */
690
- function cleanOptions(options) {
690
+ function cleanGlobalCLIOptions(options) {
691
691
  const ret = { ...options };
692
692
  delete ret['--'];
693
693
  delete ret.c;
@@ -714,6 +714,15 @@ function cleanOptions(options) {
714
714
  }
715
715
  return ret;
716
716
  }
717
+ /**
718
+ * removing builder flags before passing as command specific sub-configs
719
+ */
720
+ function cleanBuilderCLIOptions(options) {
721
+ const ret = { ...options };
722
+ delete ret.environment;
723
+ delete ret.all;
724
+ return ret;
725
+ }
717
726
  /**
718
727
  * host may be a number (like 0), should convert to string
719
728
  */
@@ -757,7 +766,7 @@ cli
757
766
  filterDuplicateOptions(options);
758
767
  // output structure is preserved even after bundling so require()
759
768
  // is ok here
760
- const { createServer } = await import('./chunks/dep-C-KAszbv.js').then(function (n) { return n.E; });
769
+ const { createServer } = await import('./chunks/dep-hQh5_mg-.js').then(function (n) { return n.I; });
761
770
  try {
762
771
  const server = await createServer({
763
772
  root,
@@ -767,7 +776,7 @@ cli
767
776
  logLevel: options.logLevel,
768
777
  clearScreen: options.clearScreen,
769
778
  optimizeDeps: { force: options.force },
770
- server: cleanOptions(options),
779
+ server: cleanGlobalCLIOptions(options),
771
780
  });
772
781
  if (!server.httpServer) {
773
782
  throw new Error('HTTP server not available');
@@ -834,20 +843,39 @@ cli
834
843
  .option('--ssrManifest [name]', `[boolean | string] emit ssr manifest json`)
835
844
  .option('--emptyOutDir', `[boolean] force empty outDir when it's outside of root`)
836
845
  .option('-w, --watch', `[boolean] rebuilds when modules have changed on disk`)
846
+ .option('--environment [name]', `[string] build a single environment`)
847
+ .option('--all', `[boolean] build all environments`)
837
848
  .action(async (root, options) => {
838
849
  filterDuplicateOptions(options);
839
- const { build } = await import('./chunks/dep-C-KAszbv.js').then(function (n) { return n.F; });
840
- const buildOptions = cleanOptions(options);
850
+ const { build, createViteBuilder } = await import('./chunks/dep-hQh5_mg-.js').then(function (n) { return n.K; });
851
+ const buildOptions = cleanGlobalCLIOptions(cleanBuilderCLIOptions(options));
852
+ const config = {
853
+ root,
854
+ base: options.base,
855
+ mode: options.mode,
856
+ configFile: options.config,
857
+ logLevel: options.logLevel,
858
+ clearScreen: options.clearScreen,
859
+ build: buildOptions,
860
+ };
841
861
  try {
842
- await build({
843
- root,
844
- base: options.base,
845
- mode: options.mode,
846
- configFile: options.config,
847
- logLevel: options.logLevel,
848
- clearScreen: options.clearScreen,
849
- build: buildOptions,
850
- });
862
+ if (options.all || options.environment) {
863
+ const builder = await createViteBuilder({}, config);
864
+ if (options.environment) {
865
+ const environment = builder.environments[options.environment];
866
+ if (!environment) {
867
+ throw new Error(`The environment ${options.environment} isn't configured.`);
868
+ }
869
+ await builder.build(environment);
870
+ }
871
+ else {
872
+ // --all: build all environments
873
+ await builder.buildEnvironments();
874
+ }
875
+ }
876
+ else {
877
+ await build(config);
878
+ }
851
879
  }
852
880
  catch (e) {
853
881
  createLogger(options.logLevel).error(colors.red(`error during build:\n${e.stack}`), { error: e });
@@ -863,7 +891,7 @@ cli
863
891
  .option('--force', `[boolean] force the optimizer to ignore the cache and re-bundle`)
864
892
  .action(async (root, options) => {
865
893
  filterDuplicateOptions(options);
866
- const { optimizeDeps } = await import('./chunks/dep-C-KAszbv.js').then(function (n) { return n.D; });
894
+ const { optimizeDeps } = await import('./chunks/dep-hQh5_mg-.js').then(function (n) { return n.J; });
867
895
  try {
868
896
  const config = await resolveConfig({
869
897
  root,
@@ -872,7 +900,8 @@ cli
872
900
  logLevel: options.logLevel,
873
901
  mode: options.mode,
874
902
  }, 'serve');
875
- await optimizeDeps(config, options.force, true);
903
+ const environment = new Environment('client', config);
904
+ await optimizeDeps(environment, options.force, true);
876
905
  }
877
906
  catch (e) {
878
907
  createLogger(options.logLevel).error(colors.red(`error when optimizing deps:\n${e.stack}`), { error: e });
@@ -889,7 +918,7 @@ cli
889
918
  .option('--outDir <dir>', `[string] output directory (default: dist)`)
890
919
  .action(async (root, options) => {
891
920
  filterDuplicateOptions(options);
892
- const { preview } = await import('./chunks/dep-C-KAszbv.js').then(function (n) { return n.G; });
921
+ const { preview } = await import('./chunks/dep-hQh5_mg-.js').then(function (n) { return n.L; });
893
922
  try {
894
923
  const server = await preview({
895
924
  root,