vite 3.0.0-alpha.0 → 3.0.0-alpha.3

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.
Files changed (92) hide show
  1. package/LICENSE.md +1 -1
  2. package/bin/vite.js +5 -5
  3. package/client.d.ts +4 -2
  4. package/dist/client/client.mjs +23 -19
  5. package/dist/client/client.mjs.map +1 -1
  6. package/dist/node/build.d.ts +178 -0
  7. package/dist/node/certificate.d.ts +2 -0
  8. package/dist/node/chunks/{dep-a9015192.js → dep-24157481.js} +20 -20
  9. package/dist/node/chunks/{dep-dfbd0b0c.js → dep-5eede05c.js} +40 -37
  10. package/dist/node/chunks/{dep-fafc4143.js → dep-6f5ac69c.js} +1681 -1636
  11. package/dist/node/chunks/{dep-2d9eaf08.js → dep-b1fc04c1.js} +27 -29
  12. package/dist/node/chunks/{dep-63fe0f22.js → dep-da8244f4.js} +12 -6
  13. package/dist/node/chunks/{dep-2056ae8a.js → dep-e8ca8d40.js} +9 -3
  14. package/dist/node/cli.d.ts +1 -0
  15. package/dist/node/cli.js +43 -48
  16. package/dist/node/config.d.ts +240 -0
  17. package/dist/node/constants.d.ts +35 -0
  18. package/dist/node/constants.js +82 -0
  19. package/dist/node/env.d.ts +3 -0
  20. package/dist/node/http.d.ts +88 -0
  21. package/dist/node/index.d.ts +12 -4
  22. package/dist/node/index.js +37 -60
  23. package/dist/node/logger.d.ts +31 -0
  24. package/dist/node/optimizer/esbuildDepPlugin.d.ts +4 -0
  25. package/dist/node/optimizer/index.d.ts +154 -0
  26. package/dist/node/optimizer/registerMissing.d.ts +3 -0
  27. package/dist/node/optimizer/scan.d.ts +8 -0
  28. package/dist/node/packages.d.ts +27 -0
  29. package/dist/node/plugin.d.ts +129 -0
  30. package/dist/node/plugins/asset.d.ts +68 -0
  31. package/dist/node/plugins/assetImportMetaUrl.d.ts +13 -0
  32. package/dist/node/plugins/clientInjections.d.ts +7 -0
  33. package/dist/node/plugins/css.d.ts +86 -0
  34. package/dist/node/plugins/dataUri.d.ts +5 -0
  35. package/dist/node/plugins/define.d.ts +3 -0
  36. package/dist/node/plugins/dynamicImportVars.d.ts +9 -0
  37. package/dist/node/plugins/ensureWatch.d.ts +5 -0
  38. package/dist/node/plugins/esbuild.d.ts +15 -0
  39. package/dist/node/plugins/html.d.ts +120 -0
  40. package/dist/node/plugins/importAnalysis.d.ts +47 -0
  41. package/dist/node/plugins/importAnalysisBuild.d.ts +16 -0
  42. package/dist/node/plugins/importMetaGlob.d.ts +34 -0
  43. package/dist/node/plugins/index.d.ts +3 -0
  44. package/dist/node/plugins/json.d.ts +23 -0
  45. package/dist/node/plugins/loadFallback.d.ts +5 -0
  46. package/dist/node/plugins/manifest.d.ts +14 -0
  47. package/dist/node/plugins/metadata.d.ts +9 -0
  48. package/dist/node/plugins/modulePreloadPolyfill.d.ts +4 -0
  49. package/dist/node/plugins/optimizedDeps.d.ts +4 -0
  50. package/dist/node/plugins/preAlias.d.ts +5 -0
  51. package/dist/node/plugins/reporter.d.ts +3 -0
  52. package/dist/node/plugins/resolve.d.ts +39 -0
  53. package/dist/node/plugins/splitVendorChunk.d.ts +12 -0
  54. package/dist/node/plugins/ssrRequireHook.d.ts +12 -0
  55. package/dist/node/plugins/terser.d.ts +3 -0
  56. package/dist/node/plugins/wasm.d.ts +4 -0
  57. package/dist/node/plugins/worker.d.ts +9 -0
  58. package/dist/node/plugins/workerImportMetaUrl.d.ts +3 -0
  59. package/dist/node/preview.d.ts +33 -0
  60. package/dist/node/publicUtils.d.ts +11 -0
  61. package/dist/node/server/hmr.d.ts +39 -0
  62. package/dist/node/server/index.d.ts +198 -0
  63. package/dist/node/server/middlewares/base.d.ts +3 -0
  64. package/dist/node/server/middlewares/compression.d.ts +1 -0
  65. package/dist/node/server/middlewares/error.d.ts +8 -0
  66. package/dist/node/server/middlewares/indexHtml.d.ts +4 -0
  67. package/dist/node/server/middlewares/proxy.d.ts +20 -0
  68. package/dist/node/server/middlewares/spaFallback.d.ts +2 -0
  69. package/dist/node/server/middlewares/static.d.ts +6 -0
  70. package/dist/node/server/middlewares/time.d.ts +2 -0
  71. package/dist/node/server/middlewares/transform.d.ts +3 -0
  72. package/dist/node/server/moduleGraph.d.ts +55 -0
  73. package/dist/node/server/openBrowser.d.ts +15 -0
  74. package/dist/node/server/pluginContainer.d.ts +41 -0
  75. package/dist/node/server/searchRoot.d.ts +8 -0
  76. package/dist/node/server/send.d.ts +10 -0
  77. package/dist/node/server/sourcemap.d.ts +11 -0
  78. package/dist/node/server/transformRequest.d.ts +14 -0
  79. package/dist/node/server/ws.d.ts +55 -0
  80. package/dist/node/ssr/ssrExternal.d.ts +11 -0
  81. package/dist/node/ssr/ssrManifestPlugin.d.ts +3 -0
  82. package/dist/node/ssr/ssrModuleLoader.d.ts +7 -0
  83. package/dist/node/ssr/ssrStacktrace.d.ts +3 -0
  84. package/dist/node/ssr/ssrTransform.d.ts +14 -0
  85. package/dist/node/utils.d.ts +144 -0
  86. package/dist/node-cjs/publicUtils.cjs +2047 -0
  87. package/dist/{node/terser.js → node-cjs/terser.cjs} +0 -0
  88. package/index.cjs +33 -0
  89. package/package.json +23 -6
  90. package/src/client/client.ts +22 -16
  91. package/src/client/tsconfig.json +1 -1
  92. package/types/importGlob.d.ts +1 -3
@@ -0,0 +1,82 @@
1
+ import path, { resolve } from 'path';
2
+ import { fileURLToPath } from 'url';
3
+
4
+ var version = "3.0.0-alpha.3";
5
+
6
+ const VERSION = version;
7
+ const DEFAULT_MAIN_FIELDS = [
8
+ 'module',
9
+ 'jsnext:main',
10
+ 'jsnext'
11
+ ];
12
+ const DEFAULT_EXTENSIONS = [
13
+ '.mjs',
14
+ '.js',
15
+ '.ts',
16
+ '.jsx',
17
+ '.tsx',
18
+ '.json'
19
+ ];
20
+ const JS_TYPES_RE = /\.(?:j|t)sx?$|\.mjs$/;
21
+ const OPTIMIZABLE_ENTRY_RE = /\.(?:m?js|ts)$/;
22
+ const SPECIAL_QUERY_RE = /[\?&](?:worker|sharedworker|raw|url)\b/;
23
+ /**
24
+ * Prefix for resolved fs paths, since windows paths may not be valid as URLs.
25
+ */
26
+ const FS_PREFIX = `/@fs/`;
27
+ /**
28
+ * Prefix for resolved Ids that are not valid browser import specifiers
29
+ */
30
+ const VALID_ID_PREFIX = `/@id/`;
31
+ /**
32
+ * Plugins that use 'virtual modules' (e.g. for helper functions), prefix the
33
+ * module ID with `\0`, a convention from the rollup ecosystem.
34
+ * This prevents other plugins from trying to process the id (like node resolution),
35
+ * and core features like sourcemaps can use this info to differentiate between
36
+ * virtual modules and regular files.
37
+ * `\0` is not a permitted char in import URLs so we have to replace them during
38
+ * import analysis. The id will be decoded back before entering the plugins pipeline.
39
+ * These encoded virtual ids are also prefixed by the VALID_ID_PREFIX, so virtual
40
+ * modules in the browser end up encoded as `/@id/__x00__{id}`
41
+ */
42
+ const NULL_BYTE_PLACEHOLDER = `__x00__`;
43
+ const CLIENT_PUBLIC_PATH = `/@vite/client`;
44
+ const ENV_PUBLIC_PATH = `/@vite/env`;
45
+ const VITE_PACKAGE_DIR = resolve(fileURLToPath(import.meta.url), '../../..');
46
+ const CLIENT_ENTRY = resolve(VITE_PACKAGE_DIR, 'dist/client/client.mjs');
47
+ const ENV_ENTRY = resolve(VITE_PACKAGE_DIR, 'dist/client/env.mjs');
48
+ const CLIENT_DIR = path.dirname(CLIENT_ENTRY);
49
+ // ** READ THIS ** before editing `KNOWN_ASSET_TYPES`.
50
+ // If you add an asset to `KNOWN_ASSET_TYPES`, make sure to also add it
51
+ // to the TypeScript declaration file `packages/vite/client.d.ts`.
52
+ const KNOWN_ASSET_TYPES = [
53
+ // images
54
+ 'png',
55
+ 'jpe?g',
56
+ 'gif',
57
+ 'svg',
58
+ 'ico',
59
+ 'webp',
60
+ 'avif',
61
+ // media
62
+ 'mp4',
63
+ 'webm',
64
+ 'ogg',
65
+ 'mp3',
66
+ 'wav',
67
+ 'flac',
68
+ 'aac',
69
+ // fonts
70
+ 'woff2?',
71
+ 'eot',
72
+ 'ttf',
73
+ 'otf',
74
+ // other
75
+ 'webmanifest',
76
+ 'pdf',
77
+ 'txt'
78
+ ];
79
+ const DEFAULT_ASSETS_RE = new RegExp(`\\.(` + KNOWN_ASSET_TYPES.join('|') + `)(\\?.*)?$`);
80
+ const DEP_VERSION_RE = /[\?&](v=[\w\.-]+)\b/;
81
+
82
+ export { CLIENT_DIR, CLIENT_ENTRY, CLIENT_PUBLIC_PATH, DEFAULT_ASSETS_RE, DEFAULT_EXTENSIONS, DEFAULT_MAIN_FIELDS, DEP_VERSION_RE, ENV_ENTRY, ENV_PUBLIC_PATH, FS_PREFIX, JS_TYPES_RE, KNOWN_ASSET_TYPES, NULL_BYTE_PLACEHOLDER, OPTIMIZABLE_ENTRY_RE, SPECIAL_QUERY_RE, VALID_ID_PREFIX, VERSION, VITE_PACKAGE_DIR };
@@ -0,0 +1,3 @@
1
+ import type { UserConfig } from './config';
2
+ export declare function loadEnv(mode: string, envDir: string, prefixes?: string | string[]): Record<string, string>;
3
+ export declare function resolveEnvPrefix({ envPrefix }: UserConfig): string[];
@@ -0,0 +1,88 @@
1
+ /// <reference types="node" />
2
+ import type { Server as HttpServer, OutgoingHttpHeaders as HttpServerHeaders } from 'http';
3
+ import type { ServerOptions as HttpsServerOptions } from 'https';
4
+ import type { Connect } from 'types/connect';
5
+ import type { ProxyOptions } from './server/middlewares/proxy';
6
+ import type { Logger } from './logger';
7
+ export interface CommonServerOptions {
8
+ /**
9
+ * Specify server port. Note if the port is already being used, Vite will
10
+ * automatically try the next available port so this may not be the actual
11
+ * port the server ends up listening on.
12
+ */
13
+ port?: number;
14
+ /**
15
+ * If enabled, vite will exit if specified port is already in use
16
+ */
17
+ strictPort?: boolean;
18
+ /**
19
+ * Specify which IP addresses the server should listen on.
20
+ * Set to 0.0.0.0 to listen on all addresses, including LAN and public addresses.
21
+ */
22
+ host?: string | boolean;
23
+ /**
24
+ * Enable TLS + HTTP/2.
25
+ * Note: this downgrades to TLS only when the proxy option is also used.
26
+ */
27
+ https?: boolean | HttpsServerOptions;
28
+ /**
29
+ * Open browser window on startup
30
+ */
31
+ open?: boolean | string;
32
+ /**
33
+ * Configure custom proxy rules for the dev server. Expects an object
34
+ * of `{ key: options }` pairs.
35
+ * Uses [`http-proxy`](https://github.com/http-party/node-http-proxy).
36
+ * Full options [here](https://github.com/http-party/node-http-proxy#options).
37
+ *
38
+ * Example `vite.config.js`:
39
+ * ``` js
40
+ * module.exports = {
41
+ * proxy: {
42
+ * // string shorthand
43
+ * '/foo': 'http://localhost:4567/foo',
44
+ * // with options
45
+ * '/api': {
46
+ * target: 'http://jsonplaceholder.typicode.com',
47
+ * changeOrigin: true,
48
+ * rewrite: path => path.replace(/^\/api/, '')
49
+ * }
50
+ * }
51
+ * }
52
+ * ```
53
+ */
54
+ proxy?: Record<string, string | ProxyOptions>;
55
+ /**
56
+ * Configure CORS for the dev server.
57
+ * Uses https://github.com/expressjs/cors.
58
+ * Set to `true` to allow all methods from any origin, or configure separately
59
+ * using an object.
60
+ */
61
+ cors?: CorsOptions | boolean;
62
+ /**
63
+ * Specify server response headers.
64
+ */
65
+ headers?: HttpServerHeaders;
66
+ }
67
+ /**
68
+ * https://github.com/expressjs/cors#configuration-options
69
+ */
70
+ export interface CorsOptions {
71
+ origin?: CorsOrigin | ((origin: string, cb: (err: Error, origins: CorsOrigin) => void) => void);
72
+ methods?: string | string[];
73
+ allowedHeaders?: string | string[];
74
+ exposedHeaders?: string | string[];
75
+ credentials?: boolean;
76
+ maxAge?: number;
77
+ preflightContinue?: boolean;
78
+ optionsSuccessStatus?: number;
79
+ }
80
+ export declare type CorsOrigin = boolean | string | RegExp | (string | RegExp)[];
81
+ export declare function resolveHttpServer({ proxy }: CommonServerOptions, app: Connect.Server, httpsOptions?: HttpsServerOptions): Promise<HttpServer>;
82
+ export declare function resolveHttpsConfig(https: boolean | HttpsServerOptions | undefined, cacheDir: string): Promise<HttpsServerOptions | undefined>;
83
+ export declare function httpServerStart(httpServer: HttpServer, serverOptions: {
84
+ port: number;
85
+ strictPort: boolean | undefined;
86
+ host: string | undefined;
87
+ logger: Logger;
88
+ }): Promise<number>;
@@ -47,7 +47,6 @@ import type { TransformResult as TransformResult_3 } from 'esbuild';
47
47
  import type * as url from 'url';
48
48
  import type { URL as URL_2 } from 'url';
49
49
  import type { WatcherOptions } from 'rollup';
50
- import type { Worker as Worker_2 } from 'okie';
51
50
  import type { ZlibOptions } from 'zlib';
52
51
 
53
52
  export declare interface Alias {
@@ -657,7 +656,7 @@ export declare interface FileSystemServeOptions {
657
656
  deny?: string[];
658
657
  }
659
658
 
660
- export declare function formatPostcssSourceMap(rawMap: ExistingRawSourceMap, file: string): ExistingRawSourceMap;
659
+ export declare function formatPostcssSourceMap(rawMap: ExistingRawSourceMap, file: string): Promise<ExistingRawSourceMap>;
661
660
 
662
661
  export declare class FSWatcher extends EventEmitter implements fs.FSWatcher {
663
662
  options: WatchOptions
@@ -1150,7 +1149,7 @@ export declare interface JsonOptions {
1150
1149
  export declare interface KnownAsTypeMap {
1151
1150
  raw: string
1152
1151
  url: string
1153
- worker: Worker_2<any, any>
1152
+ worker: Worker
1154
1153
  }
1155
1154
 
1156
1155
  export declare type LibraryFormats = 'es' | 'cjs' | 'umd' | 'iife';
@@ -1214,6 +1213,8 @@ export declare interface ManifestChunk {
1214
1213
 
1215
1214
  export declare type Matcher = AnymatchPattern | AnymatchPattern[]
1216
1215
 
1216
+ export declare function mergeAlias(a?: AliasOptions, b?: AliasOptions): AliasOptions | undefined;
1217
+
1217
1218
  export declare function mergeConfig(defaults: Record<string, any>, overrides: Record<string, any>, isRoot?: boolean): Record<string, any>;
1218
1219
 
1219
1220
  export declare class ModuleGraph {
@@ -1473,7 +1474,7 @@ export declare interface PreviewServer {
1473
1474
  /**
1474
1475
  * native Node http server instance
1475
1476
  */
1476
- httpServer: Server;
1477
+ httpServer: http.Server;
1477
1478
  /**
1478
1479
  * Print server urls
1479
1480
  */
@@ -1536,6 +1537,7 @@ export declare type ResolvedConfig = Readonly<Omit<UserConfig, 'plugins' | 'asse
1536
1537
  optimizeDeps: DepOptimizationOptions;
1537
1538
  /* Excluded from this release type: packageCache */
1538
1539
  worker: ResolveWorkerOptions;
1540
+ spa: boolean;
1539
1541
  }>;
1540
1542
 
1541
1543
  export declare interface ResolvedPreviewOptions extends PreviewOptions {
@@ -2201,6 +2203,12 @@ export declare interface UserConfig {
2201
2203
  */
2202
2204
  rollupOptions?: Omit<RollupOptions, 'plugins' | 'input' | 'onwarn' | 'preserveEntrySignatures'>;
2203
2205
  };
2206
+ /**
2207
+ * Whether your application is a Single Page Application (SPA). Set to `false`
2208
+ * for other kinds of apps like MPAs.
2209
+ * @default true
2210
+ */
2211
+ spa?: boolean;
2204
2212
  }
2205
2213
 
2206
2214
  export declare type UserConfigExport = UserConfig | Promise<UserConfig> | UserConfigFn;
@@ -1,33 +1,34 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var index = require('./chunks/dep-fafc4143.js');
6
- require('fs');
7
- require('path');
8
- require('url');
9
- require('perf_hooks');
10
- require('tty');
11
- require('os');
12
- require('esbuild');
13
- require('events');
14
- require('assert');
15
- require('resolve');
16
- require('util');
17
- require('net');
18
- require('http');
19
- require('stream');
20
- require('child_process');
21
- require('crypto');
22
- require('module');
23
- require('buffer');
24
- require('querystring');
25
- require('zlib');
26
- require('https');
27
- require('tls');
28
- require('worker_threads');
29
- require('readline');
1
+ export { b as build, i as createLogger, c as createServer, d as defineConfig, f as formatPostcssSourceMap, l as loadConfigFromFile, k as loadEnv, g as mergeAlias, m as mergeConfig, n as normalizePath, o as optimizeDeps, p as preview, e as resolveConfig, q as resolveEnvPrefix, a as resolvePackageData, r as resolvePackageEntry, j as searchForWorkspaceRoot, h as send, s as sortUserPlugins, t as transformWithEsbuild } from './chunks/dep-6f5ac69c.js';
2
+ import 'fs';
3
+ import 'path';
4
+ import 'url';
5
+ import 'perf_hooks';
6
+ import 'module';
7
+ import 'tty';
8
+ import 'esbuild';
9
+ import 'events';
10
+ import 'assert';
11
+ import 'resolve';
12
+ import 'util';
13
+ import 'net';
14
+ import 'http';
15
+ import 'stream';
16
+ import 'os';
17
+ import 'child_process';
18
+ import 'crypto';
19
+ import './constants.js';
20
+ import 'buffer';
21
+ import 'querystring';
22
+ import 'zlib';
23
+ import 'https';
24
+ import 'tls';
25
+ import 'worker_threads';
26
+ import 'readline';
30
27
 
28
+ // This file will be built for both ESM and CJS. Avoid relying on other modules as possible.
29
+ const cssLangs = `\\.(css|less|sass|scss|styl|stylus|pcss|postcss)($|\\?)`;
30
+ const cssLangRE = new RegExp(cssLangs);
31
+ const isCSSRequest = (request) => cssLangRE.test(request);
31
32
  // Use splitVendorChunkPlugin() to get the same manualChunks strategy as Vite 2.7
32
33
  // We don't recommend using this strategy as a general solution moving forward
33
34
  // splitVendorChunk is a simple index/vendor strategy that was used in Vite
@@ -44,11 +45,10 @@ class SplitVendorChunkCache {
44
45
  }
45
46
  }
46
47
  function splitVendorChunk(options = {}) {
47
- var _a;
48
- const cache = (_a = options.cache) !== null && _a !== void 0 ? _a : new SplitVendorChunkCache();
48
+ const cache = options.cache ?? new SplitVendorChunkCache();
49
49
  return (id, { getModuleInfo }) => {
50
50
  if (id.includes('node_modules') &&
51
- !index.isCSSRequest(id) &&
51
+ !isCSSRequest(id) &&
52
52
  staticImportedByEntry(id, getModuleInfo, cache.cache)) {
53
53
  return 'vendor';
54
54
  }
@@ -79,11 +79,10 @@ function staticImportedByEntry(id, getModuleInfo, cache, importStack = []) {
79
79
  function splitVendorChunkPlugin() {
80
80
  const caches = [];
81
81
  function createSplitVendorChunk(output, config) {
82
- var _a;
83
82
  const cache = new SplitVendorChunkCache();
84
83
  caches.push(cache);
85
- const build = (_a = config.build) !== null && _a !== void 0 ? _a : {};
86
- const format = output === null || output === void 0 ? void 0 : output.format;
84
+ const build = config.build ?? {};
85
+ const format = output?.format;
87
86
  if (!build.ssr && !build.lib && format !== 'umd' && format !== 'iife') {
88
87
  return splitVendorChunk({ cache });
89
88
  }
@@ -91,8 +90,7 @@ function splitVendorChunkPlugin() {
91
90
  return {
92
91
  name: 'vite:split-vendor-chunk',
93
92
  config(config) {
94
- var _a, _b;
95
- let outputs = (_b = (_a = config === null || config === void 0 ? void 0 : config.build) === null || _a === void 0 ? void 0 : _a.rollupOptions) === null || _b === void 0 ? void 0 : _b.output;
93
+ let outputs = config?.build?.rollupOptions?.output;
96
94
  if (outputs) {
97
95
  outputs = Array.isArray(outputs) ? outputs : [outputs];
98
96
  for (const output of outputs) {
@@ -102,8 +100,7 @@ function splitVendorChunkPlugin() {
102
100
  if (typeof output.manualChunks === 'function') {
103
101
  const userManualChunks = output.manualChunks;
104
102
  output.manualChunks = (id, api) => {
105
- var _a;
106
- return (_a = userManualChunks(id, api)) !== null && _a !== void 0 ? _a : viteManualChunks(id, api);
103
+ return userManualChunks(id, api) ?? viteManualChunks(id, api);
107
104
  };
108
105
  }
109
106
  // else, leave the object form of manualChunks untouched, as
@@ -133,24 +130,4 @@ function splitVendorChunkPlugin() {
133
130
  };
134
131
  }
135
132
 
136
- exports.build = index.build;
137
- exports.createLogger = index.createLogger;
138
- exports.createServer = index.createServer;
139
- exports.defineConfig = index.defineConfig;
140
- exports.formatPostcssSourceMap = index.formatPostcssSourceMap;
141
- exports.loadConfigFromFile = index.loadConfigFromFile;
142
- exports.loadEnv = index.loadEnv;
143
- exports.mergeConfig = index.mergeConfig;
144
- exports.normalizePath = index.normalizePath;
145
- exports.optimizeDeps = index.optimizeDeps;
146
- exports.preview = index.preview;
147
- exports.resolveConfig = index.resolveConfig;
148
- exports.resolveEnvPrefix = index.resolveEnvPrefix;
149
- exports.resolvePackageData = index.resolvePackageData;
150
- exports.resolvePackageEntry = index.resolvePackageEntry;
151
- exports.searchForWorkspaceRoot = index.searchForWorkspaceRoot;
152
- exports.send = index.send;
153
- exports.sortUserPlugins = index.sortUserPlugins;
154
- exports.transformWithEsbuild = index.transformWithEsbuild;
155
- exports.splitVendorChunk = splitVendorChunk;
156
- exports.splitVendorChunkPlugin = splitVendorChunkPlugin;
133
+ export { splitVendorChunk, splitVendorChunkPlugin };
@@ -0,0 +1,31 @@
1
+ /// <reference types="node" />
2
+ import type { Server } from 'net';
3
+ import type { RollupError } from 'rollup';
4
+ import type { CommonServerOptions } from './http';
5
+ import type { ResolvedConfig } from '.';
6
+ export declare type LogType = 'error' | 'warn' | 'info';
7
+ export declare type LogLevel = LogType | 'silent';
8
+ export interface Logger {
9
+ info(msg: string, options?: LogOptions): void;
10
+ warn(msg: string, options?: LogOptions): void;
11
+ warnOnce(msg: string, options?: LogOptions): void;
12
+ error(msg: string, options?: LogErrorOptions): void;
13
+ clearScreen(type: LogType): void;
14
+ hasErrorLogged(error: Error | RollupError): boolean;
15
+ hasWarned: boolean;
16
+ }
17
+ export interface LogOptions {
18
+ clear?: boolean;
19
+ timestamp?: boolean;
20
+ }
21
+ export interface LogErrorOptions extends LogOptions {
22
+ error?: Error | RollupError | null;
23
+ }
24
+ export declare const LogLevels: Record<LogLevel, number>;
25
+ export interface LoggerOptions {
26
+ prefix?: string;
27
+ allowClearScreen?: boolean;
28
+ customLogger?: Logger;
29
+ }
30
+ export declare function createLogger(level?: LogLevel, options?: LoggerOptions): Logger;
31
+ export declare function printCommonServerUrls(server: Server, options: CommonServerOptions, config: ResolvedConfig): void;
@@ -0,0 +1,4 @@
1
+ import type { Plugin } from 'esbuild';
2
+ import type { ResolvedConfig } from '..';
3
+ import type { ExportsData } from '.';
4
+ export declare function esbuildDepPlugin(qualified: Record<string, string>, exportsData: Record<string, ExportsData>, config: ResolvedConfig): Plugin;
@@ -0,0 +1,154 @@
1
+ import type { BuildOptions as EsbuildBuildOptions } from 'esbuild';
2
+ import { parse } from 'es-module-lexer';
3
+ import type { ResolvedConfig } from '../config';
4
+ export declare const debuggerViteDeps: (...args: any[]) => any;
5
+ export declare type ExportsData = ReturnType<typeof parse> & {
6
+ hasReExports?: true;
7
+ };
8
+ export interface OptimizedDeps {
9
+ metadata: DepOptimizationMetadata;
10
+ scanProcessing?: Promise<void>;
11
+ registerMissingImport: (id: string, resolved: string) => OptimizedDepInfo;
12
+ }
13
+ export interface DepOptimizationOptions {
14
+ /**
15
+ * By default, Vite will crawl your `index.html` to detect dependencies that
16
+ * need to be pre-bundled. If `build.rollupOptions.input` is specified, Vite
17
+ * will crawl those entry points instead.
18
+ *
19
+ * If neither of these fit your needs, you can specify custom entries using
20
+ * this option - the value should be a fast-glob pattern or array of patterns
21
+ * (https://github.com/mrmlnc/fast-glob#basic-syntax) that are relative from
22
+ * vite project root. This will overwrite default entries inference.
23
+ */
24
+ entries?: string | string[];
25
+ /**
26
+ * Force optimize listed dependencies (must be resolvable import paths,
27
+ * cannot be globs).
28
+ */
29
+ include?: string[];
30
+ /**
31
+ * Do not optimize these dependencies (must be resolvable import paths,
32
+ * cannot be globs).
33
+ */
34
+ exclude?: string[];
35
+ /**
36
+ * Options to pass to esbuild during the dep scanning and optimization
37
+ *
38
+ * Certain options are omitted since changing them would not be compatible
39
+ * with Vite's dep optimization.
40
+ *
41
+ * - `external` is also omitted, use Vite's `optimizeDeps.exclude` option
42
+ * - `plugins` are merged with Vite's dep plugin
43
+ *
44
+ * https://esbuild.github.io/api
45
+ */
46
+ esbuildOptions?: Omit<EsbuildBuildOptions, 'bundle' | 'entryPoints' | 'external' | 'write' | 'watch' | 'outdir' | 'outfile' | 'outbase' | 'outExtension' | 'metafile'>;
47
+ /**
48
+ * List of file extensions that can be optimized. A corresponding esbuild
49
+ * plugin must exist to handle the specific extension.
50
+ *
51
+ * By default, Vite can optimize `.mjs`, `.js`, and `.ts` files. This option
52
+ * allows specifying additional extensions.
53
+ *
54
+ * @experimental
55
+ */
56
+ extensions?: string[];
57
+ /**
58
+ * Disables dependencies optimizations
59
+ * @default false
60
+ * @experimental
61
+ */
62
+ disabled?: boolean;
63
+ }
64
+ export interface DepOptimizationResult {
65
+ metadata: DepOptimizationMetadata;
66
+ /**
67
+ * When doing a re-run, if there are newly discovered dependendencies
68
+ * the page reload will be delayed until the next rerun so we need
69
+ * to be able to discard the result
70
+ */
71
+ commit: () => Promise<void>;
72
+ cancel: () => void;
73
+ }
74
+ export interface DepOptimizationProcessing {
75
+ promise: Promise<void>;
76
+ resolve: () => void;
77
+ }
78
+ export interface OptimizedDepInfo {
79
+ id: string;
80
+ file: string;
81
+ src?: string;
82
+ needsInterop?: boolean;
83
+ browserHash?: string;
84
+ fileHash?: string;
85
+ /**
86
+ * During optimization, ids can still be resolved to their final location
87
+ * but the bundles may not yet be saved to disk
88
+ */
89
+ processing?: Promise<void>;
90
+ }
91
+ export interface DepOptimizationMetadata {
92
+ /**
93
+ * The main hash is determined by user config and dependency lockfiles.
94
+ * This is checked on server startup to avoid unnecessary re-bundles.
95
+ */
96
+ hash: string;
97
+ /**
98
+ * The browser hash is determined by the main hash plus additional dependencies
99
+ * discovered at runtime. This is used to invalidate browser requests to
100
+ * optimized deps.
101
+ */
102
+ browserHash: string;
103
+ /**
104
+ * Metadata for each already optimized dependency
105
+ */
106
+ optimized: Record<string, OptimizedDepInfo>;
107
+ /**
108
+ * Metadata for non-entry optimized chunks and dynamic imports
109
+ */
110
+ chunks: Record<string, OptimizedDepInfo>;
111
+ /**
112
+ * Metadata for each newly discovered dependency after processing
113
+ */
114
+ discovered: Record<string, OptimizedDepInfo>;
115
+ /**
116
+ * OptimizedDepInfo list
117
+ */
118
+ depInfoList: OptimizedDepInfo[];
119
+ }
120
+ /**
121
+ * Used by Vite CLI when running `vite optimize`
122
+ */
123
+ export declare function optimizeDeps(config: ResolvedConfig, force?: boolean | undefined, asCommand?: boolean): Promise<DepOptimizationMetadata>;
124
+ export declare function createOptimizedDepsMetadata(config: ResolvedConfig, timestamp?: string): DepOptimizationMetadata;
125
+ export declare function addOptimizedDepInfo(metadata: DepOptimizationMetadata, type: 'optimized' | 'discovered' | 'chunks', depInfo: OptimizedDepInfo): OptimizedDepInfo;
126
+ /**
127
+ * Creates the initial dep optimization metadata, loading it from the deps cache
128
+ * if it exists and pre-bundling isn't forced
129
+ */
130
+ export declare function loadCachedDepOptimizationMetadata(config: ResolvedConfig, force?: boolean | undefined, asCommand?: boolean): DepOptimizationMetadata | undefined;
131
+ /**
132
+ * Initial optimizeDeps at server start. Perform a fast scan using esbuild to
133
+ * find deps to pre-bundle and include user hard-coded dependencies
134
+ */
135
+ export declare function discoverProjectDependencies(config: ResolvedConfig, timestamp?: string): Promise<Record<string, OptimizedDepInfo>>;
136
+ export declare function depsLogString(qualifiedIds: string[]): string;
137
+ /**
138
+ * Internally, Vite uses this function to prepare a optimizeDeps run. When Vite starts, we can get
139
+ * the metadata and start the server without waiting for the optimizeDeps processing to be completed
140
+ */
141
+ export declare function runOptimizeDeps(config: ResolvedConfig, depsInfo: Record<string, OptimizedDepInfo>): Promise<DepOptimizationResult>;
142
+ export declare function findKnownImports(config: ResolvedConfig): Promise<string[]>;
143
+ export declare function newDepOptimizationProcessing(): DepOptimizationProcessing;
144
+ export declare function depsFromOptimizedDepInfo(depsInfo: Record<string, OptimizedDepInfo>): {
145
+ [k: string]: string;
146
+ };
147
+ export declare function getOptimizedDepPath(id: string, config: ResolvedConfig): string;
148
+ export declare function getDepsCacheDir(config: ResolvedConfig): string;
149
+ export declare function isOptimizedDepFile(id: string, config: ResolvedConfig): boolean;
150
+ export declare function createIsOptimizedDepUrl(config: ResolvedConfig): (url: string) => boolean;
151
+ export declare function getDepHash(config: ResolvedConfig): string;
152
+ export declare function optimizedDepInfoFromId(metadata: DepOptimizationMetadata, id: string): OptimizedDepInfo | undefined;
153
+ export declare function optimizedDepInfoFromFile(metadata: DepOptimizationMetadata, file: string): OptimizedDepInfo | undefined;
154
+ export declare function optimizedDepNeedsInterop(metadata: DepOptimizationMetadata, file: string): Promise<boolean | undefined>;
@@ -0,0 +1,3 @@
1
+ import type { ViteDevServer } from '..';
2
+ import type { OptimizedDeps } from '.';
3
+ export declare function createOptimizedDeps(server: ViteDevServer): OptimizedDeps;
@@ -0,0 +1,8 @@
1
+ import type { ResolvedConfig } from '..';
2
+ export declare const importsRE: RegExp;
3
+ export declare function scanImports(config: ResolvedConfig): Promise<{
4
+ deps: Record<string, string>;
5
+ missing: Record<string, string>;
6
+ }>;
7
+ export declare const scriptRE: RegExp;
8
+ export declare const commentRE: RegExp;
@@ -0,0 +1,27 @@
1
+ import type { ResolvedConfig } from './config';
2
+ import type { Plugin } from './plugin';
3
+ /** Cache for package.json resolution and package.json contents */
4
+ export declare type PackageCache = Map<string, PackageData>;
5
+ export interface PackageData {
6
+ dir: string;
7
+ hasSideEffects: (id: string) => boolean | 'no-treeshake';
8
+ webResolvedImports: Record<string, string | undefined>;
9
+ nodeResolvedImports: Record<string, string | undefined>;
10
+ setResolvedCache: (key: string, entry: string, targetWeb: boolean) => void;
11
+ getResolvedCache: (key: string, targetWeb: boolean) => string | undefined;
12
+ data: {
13
+ [field: string]: any;
14
+ name: string;
15
+ type: string;
16
+ version: string;
17
+ main: string;
18
+ module: string;
19
+ browser: string | Record<string, string | false>;
20
+ exports: string | Record<string, any> | string[];
21
+ dependencies: Record<string, string>;
22
+ };
23
+ }
24
+ export declare function invalidatePackageData(packageCache: PackageCache, pkgPath: string): void;
25
+ export declare function resolvePackageData(id: string, basedir: string, preserveSymlinks?: boolean, packageCache?: PackageCache): PackageData | null;
26
+ export declare function loadPackageData(pkgPath: string, preserveSymlinks?: boolean, packageCache?: PackageCache): PackageData;
27
+ export declare function watchPackageDataPlugin(config: ResolvedConfig): Plugin;