vite 5.3.0-beta.0 → 5.3.0-beta.2
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/LICENSE.md +111 -144
- package/dist/client/client.mjs +608 -606
- package/dist/client/env.mjs +18 -24
- package/dist/node/chunks/{dep-CTAUzmEN.js → dep-CkqaOKeN.js} +1 -1
- package/dist/node/chunks/{dep-BBErwUJM.js → dep-DxsHXWQ1.js} +23862 -20690
- package/dist/node/chunks/{dep-BPjeYeh_.js → dep-E0jGEM7W.js} +1 -1
- package/dist/node/cli.js +235 -244
- package/dist/node/constants.js +79 -83
- package/dist/node/index.d.ts +1 -0
- package/dist/node/index.js +186 -198
- package/dist/node/runtime.js +139 -99
- package/dist/node-cjs/publicUtils.cjs +514 -575
- package/package.json +11 -12
- package/dist/client/client.mjs.map +0 -1
- package/dist/client/env.mjs.map +0 -1
package/dist/node/cli.js
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
import path from 'node:path';
|
2
|
-
import
|
2
|
+
import fs__default 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-
|
5
|
+
import { A as colors, v as createLogger, r as resolveConfig } from './chunks/dep-DxsHXWQ1.js';
|
6
6
|
import { VERSION } from './constants.js';
|
7
7
|
import 'node:fs/promises';
|
8
8
|
import 'node:url';
|
@@ -12,7 +12,9 @@ import 'tty';
|
|
12
12
|
import 'path';
|
13
13
|
import 'esbuild';
|
14
14
|
import 'fs';
|
15
|
-
import '
|
15
|
+
import 'node:events';
|
16
|
+
import 'node:stream';
|
17
|
+
import 'node:string_decoder';
|
16
18
|
import 'node:child_process';
|
17
19
|
import 'node:http';
|
18
20
|
import 'node:https';
|
@@ -33,13 +35,13 @@ import 'node:v8';
|
|
33
35
|
import 'node:worker_threads';
|
34
36
|
import 'node:buffer';
|
35
37
|
import 'rollup/parseAst';
|
36
|
-
import 'node:events';
|
37
38
|
import 'querystring';
|
38
39
|
import 'node:readline';
|
39
40
|
import 'zlib';
|
40
41
|
import 'buffer';
|
41
42
|
import 'https';
|
42
43
|
import 'tls';
|
44
|
+
import 'assert';
|
43
45
|
import 'node:zlib';
|
44
46
|
|
45
47
|
function toArr(any) {
|
@@ -655,269 +657,258 @@ class CAC extends EventEmitter {
|
|
655
657
|
|
656
658
|
const cac = (name = "") => new CAC(name);
|
657
659
|
|
658
|
-
const cli = cac(
|
660
|
+
const cli = cac("vite");
|
659
661
|
let profileSession = global.__vite_profile_session;
|
660
662
|
let profileCount = 0;
|
661
663
|
const stopProfiler = (log) => {
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
|
664
|
+
if (!profileSession) return;
|
665
|
+
return new Promise((res, rej) => {
|
666
|
+
profileSession.post("Profiler.stop", (err, { profile }) => {
|
667
|
+
if (!err) {
|
668
|
+
const outPath = path.resolve(
|
669
|
+
`./vite-profile-${profileCount++}.cpuprofile`
|
670
|
+
);
|
671
|
+
fs__default.writeFileSync(outPath, JSON.stringify(profile));
|
672
|
+
log(
|
673
|
+
colors.yellow(
|
674
|
+
`CPU profile written to ${colors.white(colors.dim(outPath))}`
|
675
|
+
)
|
676
|
+
);
|
677
|
+
profileSession = void 0;
|
678
|
+
res();
|
679
|
+
} else {
|
680
|
+
rej(err);
|
681
|
+
}
|
678
682
|
});
|
683
|
+
});
|
679
684
|
};
|
680
685
|
const filterDuplicateOptions = (options) => {
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
}
|
686
|
+
for (const [key, value] of Object.entries(options)) {
|
687
|
+
if (Array.isArray(value)) {
|
688
|
+
options[key] = value[value.length - 1];
|
685
689
|
}
|
690
|
+
}
|
686
691
|
};
|
687
|
-
/**
|
688
|
-
* removing global flags before passing as command specific sub-configs
|
689
|
-
*/
|
690
692
|
function cleanOptions(options) {
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
? true
|
711
|
-
: sourcemap === 'false'
|
712
|
-
? false
|
713
|
-
: ret.sourcemap;
|
714
|
-
}
|
715
|
-
return ret;
|
693
|
+
const ret = { ...options };
|
694
|
+
delete ret["--"];
|
695
|
+
delete ret.c;
|
696
|
+
delete ret.config;
|
697
|
+
delete ret.base;
|
698
|
+
delete ret.l;
|
699
|
+
delete ret.logLevel;
|
700
|
+
delete ret.clearScreen;
|
701
|
+
delete ret.d;
|
702
|
+
delete ret.debug;
|
703
|
+
delete ret.f;
|
704
|
+
delete ret.filter;
|
705
|
+
delete ret.m;
|
706
|
+
delete ret.mode;
|
707
|
+
if ("sourcemap" in ret) {
|
708
|
+
const sourcemap = ret.sourcemap;
|
709
|
+
ret.sourcemap = sourcemap === "true" ? true : sourcemap === "false" ? false : ret.sourcemap;
|
710
|
+
}
|
711
|
+
return ret;
|
716
712
|
}
|
717
|
-
/**
|
718
|
-
* host may be a number (like 0), should convert to string
|
719
|
-
*/
|
720
713
|
const convertHost = (v) => {
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
714
|
+
if (typeof v === "number") {
|
715
|
+
return String(v);
|
716
|
+
}
|
717
|
+
return v;
|
725
718
|
};
|
726
|
-
/**
|
727
|
-
* base may be a number (like 0), should convert to empty string
|
728
|
-
*/
|
729
719
|
const convertBase = (v) => {
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
|
720
|
+
if (v === 0) {
|
721
|
+
return "";
|
722
|
+
}
|
723
|
+
return v;
|
734
724
|
};
|
735
|
-
cli
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
|
740
|
-
|
741
|
-
|
742
|
-
|
743
|
-
|
744
|
-
|
745
|
-
|
746
|
-
|
747
|
-
|
748
|
-
|
749
|
-
|
750
|
-
|
751
|
-
|
752
|
-
|
753
|
-
|
754
|
-
|
755
|
-
.
|
756
|
-
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
const
|
761
|
-
|
762
|
-
|
763
|
-
|
764
|
-
|
765
|
-
|
766
|
-
|
767
|
-
|
768
|
-
|
769
|
-
|
770
|
-
|
771
|
-
|
772
|
-
|
773
|
-
|
774
|
-
|
775
|
-
|
776
|
-
|
777
|
-
|
778
|
-
|
779
|
-
|
780
|
-
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
|
786
|
-
|
787
|
-
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
|
794
|
-
|
795
|
-
|
796
|
-
|
797
|
-
|
798
|
-
|
799
|
-
profileSession.connect();
|
800
|
-
profileSession.post('Profiler.enable', () => {
|
801
|
-
profileSession.post('Profiler.start', () => {
|
802
|
-
server.config.logger.info('Profiler started');
|
803
|
-
res();
|
804
|
-
});
|
805
|
-
});
|
806
|
-
});
|
807
|
-
}
|
808
|
-
},
|
725
|
+
cli.option("-c, --config <file>", `[string] use specified config file`).option("--base <path>", `[string] public base path (default: /)`, {
|
726
|
+
type: [convertBase]
|
727
|
+
}).option("-l, --logLevel <level>", `[string] info | warn | error | silent`).option("--clearScreen", `[boolean] allow/disable clear screen when logging`).option("-d, --debug [feat]", `[string | boolean] show debug logs`).option("-f, --filter <filter>", `[string] filter debug logs`).option("-m, --mode <mode>", `[string] set env mode`);
|
728
|
+
cli.command("[root]", "start dev server").alias("serve").alias("dev").option("--host [host]", `[string] specify hostname`, { type: [convertHost] }).option("--port <port>", `[number] specify port`).option("--open [path]", `[boolean | string] open browser on startup`).option("--cors", `[boolean] enable CORS`).option("--strictPort", `[boolean] exit if specified port is already in use`).option(
|
729
|
+
"--force",
|
730
|
+
`[boolean] force the optimizer to ignore the cache and re-bundle`
|
731
|
+
).action(async (root, options) => {
|
732
|
+
filterDuplicateOptions(options);
|
733
|
+
const { createServer } = await import('./chunks/dep-DxsHXWQ1.js').then(function (n) { return n.E; });
|
734
|
+
try {
|
735
|
+
const server = await createServer({
|
736
|
+
root,
|
737
|
+
base: options.base,
|
738
|
+
mode: options.mode,
|
739
|
+
configFile: options.config,
|
740
|
+
logLevel: options.logLevel,
|
741
|
+
clearScreen: options.clearScreen,
|
742
|
+
optimizeDeps: { force: options.force },
|
743
|
+
server: cleanOptions(options)
|
744
|
+
});
|
745
|
+
if (!server.httpServer) {
|
746
|
+
throw new Error("HTTP server not available");
|
747
|
+
}
|
748
|
+
await server.listen();
|
749
|
+
const info = server.config.logger.info;
|
750
|
+
const viteStartTime = global.__vite_start_time ?? false;
|
751
|
+
const startupDurationString = viteStartTime ? colors.dim(
|
752
|
+
`ready in ${colors.reset(
|
753
|
+
colors.bold(Math.ceil(performance.now() - viteStartTime))
|
754
|
+
)} ms`
|
755
|
+
) : "";
|
756
|
+
const hasExistingLogs = process.stdout.bytesWritten > 0 || process.stderr.bytesWritten > 0;
|
757
|
+
info(
|
758
|
+
`
|
759
|
+
${colors.green(
|
760
|
+
`${colors.bold("VITE")} v${VERSION}`
|
761
|
+
)} ${startupDurationString}
|
762
|
+
`,
|
763
|
+
{
|
764
|
+
clear: !hasExistingLogs
|
765
|
+
}
|
766
|
+
);
|
767
|
+
server.printUrls();
|
768
|
+
const customShortcuts = [];
|
769
|
+
if (profileSession) {
|
770
|
+
customShortcuts.push({
|
771
|
+
key: "p",
|
772
|
+
description: "start/stop the profiler",
|
773
|
+
async action(server2) {
|
774
|
+
if (profileSession) {
|
775
|
+
await stopProfiler(server2.config.logger.info);
|
776
|
+
} else {
|
777
|
+
const inspector = await import('node:inspector').then(
|
778
|
+
(r) => r.default
|
779
|
+
);
|
780
|
+
await new Promise((res) => {
|
781
|
+
profileSession = new inspector.Session();
|
782
|
+
profileSession.connect();
|
783
|
+
profileSession.post("Profiler.enable", () => {
|
784
|
+
profileSession.post("Profiler.start", () => {
|
785
|
+
server2.config.logger.info("Profiler started");
|
786
|
+
res();
|
787
|
+
});
|
788
|
+
});
|
809
789
|
});
|
790
|
+
}
|
810
791
|
}
|
811
|
-
|
812
|
-
}
|
813
|
-
catch (e) {
|
814
|
-
const logger = createLogger(options.logLevel);
|
815
|
-
logger.error(colors.red(`error when starting dev server:\n${e.stack}`), {
|
816
|
-
error: e,
|
817
|
-
});
|
818
|
-
stopProfiler(logger.info);
|
819
|
-
process.exit(1);
|
792
|
+
});
|
820
793
|
}
|
794
|
+
server.bindCLIShortcuts({ print: true, customShortcuts });
|
795
|
+
} catch (e) {
|
796
|
+
const logger = createLogger(options.logLevel);
|
797
|
+
logger.error(colors.red(`error when starting dev server:
|
798
|
+
${e.stack}`), {
|
799
|
+
error: e
|
800
|
+
});
|
801
|
+
stopProfiler(logger.info);
|
802
|
+
process.exit(1);
|
803
|
+
}
|
821
804
|
});
|
822
|
-
|
823
|
-
|
824
|
-
|
825
|
-
|
826
|
-
|
827
|
-
|
828
|
-
|
829
|
-
|
830
|
-
|
831
|
-
|
832
|
-
|
833
|
-
|
834
|
-
|
835
|
-
|
836
|
-
|
837
|
-
|
838
|
-
|
839
|
-
|
840
|
-
|
841
|
-
|
842
|
-
|
843
|
-
|
844
|
-
|
845
|
-
|
846
|
-
|
847
|
-
|
848
|
-
|
849
|
-
|
850
|
-
|
851
|
-
|
852
|
-
|
853
|
-
|
854
|
-
|
855
|
-
|
856
|
-
|
857
|
-
|
858
|
-
|
805
|
+
cli.command("build [root]", "build for production").option("--target <target>", `[string] transpile target (default: 'modules')`).option("--outDir <dir>", `[string] output directory (default: dist)`).option(
|
806
|
+
"--assetsDir <dir>",
|
807
|
+
`[string] directory under outDir to place assets in (default: assets)`
|
808
|
+
).option(
|
809
|
+
"--assetsInlineLimit <number>",
|
810
|
+
`[number] static asset base64 inline threshold in bytes (default: 4096)`
|
811
|
+
).option(
|
812
|
+
"--ssr [entry]",
|
813
|
+
`[string] build specified entry for server-side rendering`
|
814
|
+
).option(
|
815
|
+
"--sourcemap [output]",
|
816
|
+
`[boolean | "inline" | "hidden"] output source maps for build (default: false)`
|
817
|
+
).option(
|
818
|
+
"--minify [minifier]",
|
819
|
+
`[boolean | "terser" | "esbuild"] enable/disable minification, or specify minifier to use (default: esbuild)`
|
820
|
+
).option("--manifest [name]", `[boolean | string] emit build manifest json`).option("--ssrManifest [name]", `[boolean | string] emit ssr manifest json`).option(
|
821
|
+
"--emptyOutDir",
|
822
|
+
`[boolean] force empty outDir when it's outside of root`
|
823
|
+
).option("-w, --watch", `[boolean] rebuilds when modules have changed on disk`).action(async (root, options) => {
|
824
|
+
filterDuplicateOptions(options);
|
825
|
+
const { build } = await import('./chunks/dep-DxsHXWQ1.js').then(function (n) { return n.F; });
|
826
|
+
const buildOptions = cleanOptions(options);
|
827
|
+
try {
|
828
|
+
await build({
|
829
|
+
root,
|
830
|
+
base: options.base,
|
831
|
+
mode: options.mode,
|
832
|
+
configFile: options.config,
|
833
|
+
logLevel: options.logLevel,
|
834
|
+
clearScreen: options.clearScreen,
|
835
|
+
build: buildOptions
|
836
|
+
});
|
837
|
+
} catch (e) {
|
838
|
+
createLogger(options.logLevel).error(
|
839
|
+
colors.red(`error during build:
|
840
|
+
${e.stack}`),
|
841
|
+
{ error: e }
|
842
|
+
);
|
843
|
+
process.exit(1);
|
844
|
+
} finally {
|
845
|
+
stopProfiler((message) => createLogger(options.logLevel).info(message));
|
846
|
+
}
|
859
847
|
});
|
860
|
-
|
861
|
-
|
862
|
-
|
863
|
-
|
864
|
-
|
848
|
+
cli.command("optimize [root]", "pre-bundle dependencies").option(
|
849
|
+
"--force",
|
850
|
+
`[boolean] force the optimizer to ignore the cache and re-bundle`
|
851
|
+
).action(
|
852
|
+
async (root, options) => {
|
865
853
|
filterDuplicateOptions(options);
|
866
|
-
const { optimizeDeps } = await import('./chunks/dep-
|
854
|
+
const { optimizeDeps } = await import('./chunks/dep-DxsHXWQ1.js').then(function (n) { return n.D; });
|
867
855
|
try {
|
868
|
-
|
869
|
-
|
870
|
-
|
871
|
-
|
872
|
-
|
873
|
-
|
874
|
-
|
875
|
-
|
876
|
-
|
877
|
-
|
878
|
-
|
879
|
-
|
880
|
-
|
881
|
-
|
882
|
-
|
883
|
-
|
884
|
-
|
885
|
-
|
886
|
-
|
887
|
-
|
888
|
-
|
889
|
-
|
890
|
-
|
856
|
+
const config = await resolveConfig(
|
857
|
+
{
|
858
|
+
root,
|
859
|
+
base: options.base,
|
860
|
+
configFile: options.config,
|
861
|
+
logLevel: options.logLevel,
|
862
|
+
mode: options.mode
|
863
|
+
},
|
864
|
+
"serve"
|
865
|
+
);
|
866
|
+
await optimizeDeps(config, options.force, true);
|
867
|
+
} catch (e) {
|
868
|
+
createLogger(options.logLevel).error(
|
869
|
+
colors.red(`error when optimizing deps:
|
870
|
+
${e.stack}`),
|
871
|
+
{ error: e }
|
872
|
+
);
|
873
|
+
process.exit(1);
|
874
|
+
}
|
875
|
+
}
|
876
|
+
);
|
877
|
+
cli.command("preview [root]", "locally preview production build").option("--host [host]", `[string] specify hostname`, { type: [convertHost] }).option("--port <port>", `[number] specify port`).option("--strictPort", `[boolean] exit if specified port is already in use`).option("--open [path]", `[boolean | string] open browser on startup`).option("--outDir <dir>", `[string] output directory (default: dist)`).action(
|
878
|
+
async (root, options) => {
|
891
879
|
filterDuplicateOptions(options);
|
892
|
-
const { preview } = await import('./chunks/dep-
|
880
|
+
const { preview } = await import('./chunks/dep-DxsHXWQ1.js').then(function (n) { return n.G; });
|
893
881
|
try {
|
894
|
-
|
895
|
-
|
896
|
-
|
897
|
-
|
898
|
-
|
899
|
-
|
900
|
-
|
901
|
-
|
902
|
-
|
903
|
-
|
904
|
-
|
905
|
-
|
906
|
-
|
907
|
-
|
908
|
-
|
909
|
-
|
910
|
-
|
911
|
-
|
912
|
-
}
|
913
|
-
|
914
|
-
|
915
|
-
|
916
|
-
|
917
|
-
|
918
|
-
|
919
|
-
}
|
920
|
-
|
882
|
+
const server = await preview({
|
883
|
+
root,
|
884
|
+
base: options.base,
|
885
|
+
configFile: options.config,
|
886
|
+
logLevel: options.logLevel,
|
887
|
+
mode: options.mode,
|
888
|
+
build: {
|
889
|
+
outDir: options.outDir
|
890
|
+
},
|
891
|
+
preview: {
|
892
|
+
port: options.port,
|
893
|
+
strictPort: options.strictPort,
|
894
|
+
host: options.host,
|
895
|
+
open: options.open
|
896
|
+
}
|
897
|
+
});
|
898
|
+
server.printUrls();
|
899
|
+
server.bindCLIShortcuts({ print: true });
|
900
|
+
} catch (e) {
|
901
|
+
createLogger(options.logLevel).error(
|
902
|
+
colors.red(`error when starting preview server:
|
903
|
+
${e.stack}`),
|
904
|
+
{ error: e }
|
905
|
+
);
|
906
|
+
process.exit(1);
|
907
|
+
} finally {
|
908
|
+
stopProfiler((message) => createLogger(options.logLevel).info(message));
|
909
|
+
}
|
910
|
+
}
|
911
|
+
);
|
921
912
|
cli.help();
|
922
913
|
cli.version(VERSION);
|
923
914
|
cli.parse();
|