vite 3.0.0-alpha.1 → 3.0.0-alpha.4
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 +1 -1
- package/bin/vite.js +5 -5
- package/client.d.ts +4 -2
- package/dist/client/client.mjs +23 -19
- package/dist/client/client.mjs.map +1 -1
- package/dist/node/build.d.ts +178 -0
- package/dist/node/certificate.d.ts +2 -0
- package/dist/node/chunks/{dep-a9015192.js → dep-24157481.js} +20 -20
- package/dist/node/chunks/{dep-8db43f98.js → dep-28f8c91c.js} +27 -29
- package/dist/node/chunks/{dep-99df5764.js → dep-35b61ee3.js} +12 -6
- package/dist/node/chunks/{dep-5cb039d6.js → dep-aea1d487.js} +1608 -1701
- package/dist/node/chunks/{dep-88b8fd2c.js → dep-ce833324.js} +40 -37
- package/dist/node/chunks/{dep-2056ae8a.js → dep-e8ca8d40.js} +9 -3
- package/dist/node/cli.d.ts +1 -0
- package/dist/node/cli.js +43 -48
- package/dist/node/config.d.ts +240 -0
- package/dist/node/constants.d.ts +35 -0
- package/dist/node/constants.js +82 -0
- package/dist/node/env.d.ts +3 -0
- package/dist/node/http.d.ts +88 -0
- package/dist/node/index.d.ts +28 -3
- package/dist/node/index.js +37 -60
- package/dist/node/logger.d.ts +31 -0
- package/dist/node/optimizer/esbuildDepPlugin.d.ts +4 -0
- package/dist/node/optimizer/index.d.ts +167 -0
- package/dist/node/optimizer/registerMissing.d.ts +3 -0
- package/dist/node/optimizer/scan.d.ts +8 -0
- package/dist/node/packages.d.ts +27 -0
- package/dist/node/plugin.d.ts +129 -0
- package/dist/node/plugins/asset.d.ts +68 -0
- package/dist/node/plugins/assetImportMetaUrl.d.ts +13 -0
- package/dist/node/plugins/clientInjections.d.ts +7 -0
- package/dist/node/plugins/css.d.ts +86 -0
- package/dist/node/plugins/dataUri.d.ts +5 -0
- package/dist/node/plugins/define.d.ts +3 -0
- package/dist/node/plugins/dynamicImportVars.d.ts +9 -0
- package/dist/node/plugins/ensureWatch.d.ts +5 -0
- package/dist/node/plugins/esbuild.d.ts +15 -0
- package/dist/node/plugins/html.d.ts +120 -0
- package/dist/node/plugins/importAnalysis.d.ts +47 -0
- package/dist/node/plugins/importAnalysisBuild.d.ts +16 -0
- package/dist/node/plugins/importMetaGlob.d.ts +34 -0
- package/dist/node/plugins/index.d.ts +3 -0
- package/dist/node/plugins/json.d.ts +23 -0
- package/dist/node/plugins/loadFallback.d.ts +5 -0
- package/dist/node/plugins/manifest.d.ts +14 -0
- package/dist/node/plugins/metadata.d.ts +9 -0
- package/dist/node/plugins/modulePreloadPolyfill.d.ts +4 -0
- package/dist/node/plugins/optimizedDeps.d.ts +4 -0
- package/dist/node/plugins/preAlias.d.ts +5 -0
- package/dist/node/plugins/reporter.d.ts +3 -0
- package/dist/node/plugins/resolve.d.ts +39 -0
- package/dist/node/plugins/splitVendorChunk.d.ts +12 -0
- package/dist/node/plugins/ssrRequireHook.d.ts +12 -0
- package/dist/node/plugins/terser.d.ts +3 -0
- package/dist/node/plugins/wasm.d.ts +4 -0
- package/dist/node/plugins/worker.d.ts +9 -0
- package/dist/node/plugins/workerImportMetaUrl.d.ts +3 -0
- package/dist/node/preview.d.ts +33 -0
- package/dist/node/publicUtils.d.ts +11 -0
- package/dist/node/server/hmr.d.ts +39 -0
- package/dist/node/server/index.d.ts +198 -0
- package/dist/node/server/middlewares/base.d.ts +3 -0
- package/dist/node/server/middlewares/compression.d.ts +1 -0
- package/dist/node/server/middlewares/error.d.ts +8 -0
- package/dist/node/server/middlewares/indexHtml.d.ts +4 -0
- package/dist/node/server/middlewares/proxy.d.ts +20 -0
- package/dist/node/server/middlewares/spaFallback.d.ts +2 -0
- package/dist/node/server/middlewares/static.d.ts +6 -0
- package/dist/node/server/middlewares/time.d.ts +2 -0
- package/dist/node/server/middlewares/transform.d.ts +3 -0
- package/dist/node/server/moduleGraph.d.ts +55 -0
- package/dist/node/server/openBrowser.d.ts +15 -0
- package/dist/node/server/pluginContainer.d.ts +41 -0
- package/dist/node/server/searchRoot.d.ts +8 -0
- package/dist/node/server/send.d.ts +10 -0
- package/dist/node/server/sourcemap.d.ts +11 -0
- package/dist/node/server/transformRequest.d.ts +14 -0
- package/dist/node/server/ws.d.ts +55 -0
- package/dist/node/ssr/ssrExternal.d.ts +11 -0
- package/dist/node/ssr/ssrManifestPlugin.d.ts +3 -0
- package/dist/node/ssr/ssrModuleLoader.d.ts +7 -0
- package/dist/node/ssr/ssrStacktrace.d.ts +3 -0
- package/dist/node/ssr/ssrTransform.d.ts +14 -0
- package/dist/node/utils.d.ts +144 -0
- package/dist/node-cjs/publicUtils.cjs +2047 -0
- package/dist/{node/terser.js → node-cjs/terser.cjs} +0 -0
- package/index.cjs +33 -0
- package/package.json +24 -6
- package/src/client/client.ts +22 -16
- package/src/client/tsconfig.json +1 -1
- package/types/importGlob.d.ts +1 -3
|
@@ -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>;
|
package/dist/node/index.d.ts
CHANGED
|
@@ -23,6 +23,7 @@ import type * as net from 'net';
|
|
|
23
23
|
import type { OutgoingHttpHeaders } from 'http';
|
|
24
24
|
import type { OutputBundle } from 'rollup';
|
|
25
25
|
import type { OutputChunk } from 'rollup';
|
|
26
|
+
import { parse } from 'es-module-lexer';
|
|
26
27
|
import type { PartialResolvedId } from 'rollup';
|
|
27
28
|
import type { Plugin as Plugin_3 } from 'rollup';
|
|
28
29
|
import type { PluginContext } from 'rollup';
|
|
@@ -47,7 +48,6 @@ import type { TransformResult as TransformResult_3 } from 'esbuild';
|
|
|
47
48
|
import type * as url from 'url';
|
|
48
49
|
import type { URL as URL_2 } from 'url';
|
|
49
50
|
import type { WatcherOptions } from 'rollup';
|
|
50
|
-
import type { Worker as Worker_2 } from 'okie';
|
|
51
51
|
import type { ZlibOptions } from 'zlib';
|
|
52
52
|
|
|
53
53
|
export declare interface Alias {
|
|
@@ -544,6 +544,12 @@ export declare interface DepOptimizationOptions {
|
|
|
544
544
|
* cannot be globs).
|
|
545
545
|
*/
|
|
546
546
|
exclude?: string[];
|
|
547
|
+
/**
|
|
548
|
+
* Force ESM interop when importing for these dependencies. Some legacy
|
|
549
|
+
* packages advertise themselves as ESM but use `require` internally
|
|
550
|
+
* @experimental
|
|
551
|
+
*/
|
|
552
|
+
needsInterop?: string[];
|
|
547
553
|
/**
|
|
548
554
|
* Options to pass to esbuild during the dep scanning and optimization
|
|
549
555
|
*
|
|
@@ -630,6 +636,11 @@ export declare interface ExperimentalOptions {
|
|
|
630
636
|
importGlobRestoreExtension?: boolean;
|
|
631
637
|
}
|
|
632
638
|
|
|
639
|
+
export declare type ExportsData = ReturnType<typeof parse> & {
|
|
640
|
+
hasReExports?: true;
|
|
641
|
+
jsxLoader?: true;
|
|
642
|
+
};
|
|
643
|
+
|
|
633
644
|
export declare interface FileSystemServeOptions {
|
|
634
645
|
/**
|
|
635
646
|
* Strictly restrict file accessing outside of allowing paths.
|
|
@@ -657,7 +668,7 @@ export declare interface FileSystemServeOptions {
|
|
|
657
668
|
deny?: string[];
|
|
658
669
|
}
|
|
659
670
|
|
|
660
|
-
export declare function formatPostcssSourceMap(rawMap: ExistingRawSourceMap, file: string): ExistingRawSourceMap
|
|
671
|
+
export declare function formatPostcssSourceMap(rawMap: ExistingRawSourceMap, file: string): Promise<ExistingRawSourceMap>;
|
|
661
672
|
|
|
662
673
|
export declare class FSWatcher extends EventEmitter implements fs.FSWatcher {
|
|
663
674
|
options: WatchOptions
|
|
@@ -1150,7 +1161,7 @@ export declare interface JsonOptions {
|
|
|
1150
1161
|
export declare interface KnownAsTypeMap {
|
|
1151
1162
|
raw: string
|
|
1152
1163
|
url: string
|
|
1153
|
-
worker:
|
|
1164
|
+
worker: Worker
|
|
1154
1165
|
}
|
|
1155
1166
|
|
|
1156
1167
|
export declare type LibraryFormats = 'es' | 'cjs' | 'umd' | 'iife';
|
|
@@ -1214,6 +1225,8 @@ export declare interface ManifestChunk {
|
|
|
1214
1225
|
|
|
1215
1226
|
export declare type Matcher = AnymatchPattern | AnymatchPattern[]
|
|
1216
1227
|
|
|
1228
|
+
export declare function mergeAlias(a?: AliasOptions, b?: AliasOptions): AliasOptions | undefined;
|
|
1229
|
+
|
|
1217
1230
|
export declare function mergeConfig(defaults: Record<string, any>, overrides: Record<string, any>, isRoot?: boolean): Record<string, any>;
|
|
1218
1231
|
|
|
1219
1232
|
export declare class ModuleGraph {
|
|
@@ -1280,6 +1293,11 @@ export declare interface OptimizedDepInfo {
|
|
|
1280
1293
|
* but the bundles may not yet be saved to disk
|
|
1281
1294
|
*/
|
|
1282
1295
|
processing?: Promise<void>;
|
|
1296
|
+
/**
|
|
1297
|
+
* ExportData cache, discovered deps will parse the src entry to get exports
|
|
1298
|
+
* data used both to define if interop is needed and when pre-bundling
|
|
1299
|
+
*/
|
|
1300
|
+
exportsData?: Promise<ExportsData>;
|
|
1283
1301
|
}
|
|
1284
1302
|
|
|
1285
1303
|
export declare interface OptimizedDeps {
|
|
@@ -1536,6 +1554,7 @@ export declare type ResolvedConfig = Readonly<Omit<UserConfig, 'plugins' | 'asse
|
|
|
1536
1554
|
optimizeDeps: DepOptimizationOptions;
|
|
1537
1555
|
/* Excluded from this release type: packageCache */
|
|
1538
1556
|
worker: ResolveWorkerOptions;
|
|
1557
|
+
spa: boolean;
|
|
1539
1558
|
}>;
|
|
1540
1559
|
|
|
1541
1560
|
export declare interface ResolvedPreviewOptions extends PreviewOptions {
|
|
@@ -2201,6 +2220,12 @@ export declare interface UserConfig {
|
|
|
2201
2220
|
*/
|
|
2202
2221
|
rollupOptions?: Omit<RollupOptions, 'plugins' | 'input' | 'onwarn' | 'preserveEntrySignatures'>;
|
|
2203
2222
|
};
|
|
2223
|
+
/**
|
|
2224
|
+
* Whether your application is a Single Page Application (SPA). Set to `false`
|
|
2225
|
+
* for other kinds of apps like MPAs.
|
|
2226
|
+
* @default true
|
|
2227
|
+
*/
|
|
2228
|
+
spa?: boolean;
|
|
2204
2229
|
}
|
|
2205
2230
|
|
|
2206
2231
|
export declare type UserConfigExport = UserConfig | Promise<UserConfig> | UserConfigFn;
|
package/dist/node/index.js
CHANGED
|
@@ -1,33 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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-aea1d487.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
|
-
|
|
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
|
-
!
|
|
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 =
|
|
86
|
-
const format = output
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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,167 @@
|
|
|
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
|
+
jsxLoader?: true;
|
|
8
|
+
};
|
|
9
|
+
export interface OptimizedDeps {
|
|
10
|
+
metadata: DepOptimizationMetadata;
|
|
11
|
+
scanProcessing?: Promise<void>;
|
|
12
|
+
registerMissingImport: (id: string, resolved: string) => OptimizedDepInfo;
|
|
13
|
+
}
|
|
14
|
+
export interface DepOptimizationOptions {
|
|
15
|
+
/**
|
|
16
|
+
* By default, Vite will crawl your `index.html` to detect dependencies that
|
|
17
|
+
* need to be pre-bundled. If `build.rollupOptions.input` is specified, Vite
|
|
18
|
+
* will crawl those entry points instead.
|
|
19
|
+
*
|
|
20
|
+
* If neither of these fit your needs, you can specify custom entries using
|
|
21
|
+
* this option - the value should be a fast-glob pattern or array of patterns
|
|
22
|
+
* (https://github.com/mrmlnc/fast-glob#basic-syntax) that are relative from
|
|
23
|
+
* vite project root. This will overwrite default entries inference.
|
|
24
|
+
*/
|
|
25
|
+
entries?: string | string[];
|
|
26
|
+
/**
|
|
27
|
+
* Force optimize listed dependencies (must be resolvable import paths,
|
|
28
|
+
* cannot be globs).
|
|
29
|
+
*/
|
|
30
|
+
include?: string[];
|
|
31
|
+
/**
|
|
32
|
+
* Do not optimize these dependencies (must be resolvable import paths,
|
|
33
|
+
* cannot be globs).
|
|
34
|
+
*/
|
|
35
|
+
exclude?: string[];
|
|
36
|
+
/**
|
|
37
|
+
* Force ESM interop when importing for these dependencies. Some legacy
|
|
38
|
+
* packages advertise themselves as ESM but use `require` internally
|
|
39
|
+
* @experimental
|
|
40
|
+
*/
|
|
41
|
+
needsInterop?: string[];
|
|
42
|
+
/**
|
|
43
|
+
* Options to pass to esbuild during the dep scanning and optimization
|
|
44
|
+
*
|
|
45
|
+
* Certain options are omitted since changing them would not be compatible
|
|
46
|
+
* with Vite's dep optimization.
|
|
47
|
+
*
|
|
48
|
+
* - `external` is also omitted, use Vite's `optimizeDeps.exclude` option
|
|
49
|
+
* - `plugins` are merged with Vite's dep plugin
|
|
50
|
+
*
|
|
51
|
+
* https://esbuild.github.io/api
|
|
52
|
+
*/
|
|
53
|
+
esbuildOptions?: Omit<EsbuildBuildOptions, 'bundle' | 'entryPoints' | 'external' | 'write' | 'watch' | 'outdir' | 'outfile' | 'outbase' | 'outExtension' | 'metafile'>;
|
|
54
|
+
/**
|
|
55
|
+
* List of file extensions that can be optimized. A corresponding esbuild
|
|
56
|
+
* plugin must exist to handle the specific extension.
|
|
57
|
+
*
|
|
58
|
+
* By default, Vite can optimize `.mjs`, `.js`, and `.ts` files. This option
|
|
59
|
+
* allows specifying additional extensions.
|
|
60
|
+
*
|
|
61
|
+
* @experimental
|
|
62
|
+
*/
|
|
63
|
+
extensions?: string[];
|
|
64
|
+
/**
|
|
65
|
+
* Disables dependencies optimizations
|
|
66
|
+
* @default false
|
|
67
|
+
* @experimental
|
|
68
|
+
*/
|
|
69
|
+
disabled?: boolean;
|
|
70
|
+
}
|
|
71
|
+
export interface DepOptimizationResult {
|
|
72
|
+
metadata: DepOptimizationMetadata;
|
|
73
|
+
/**
|
|
74
|
+
* When doing a re-run, if there are newly discovered dependendencies
|
|
75
|
+
* the page reload will be delayed until the next rerun so we need
|
|
76
|
+
* to be able to discard the result
|
|
77
|
+
*/
|
|
78
|
+
commit: () => Promise<void>;
|
|
79
|
+
cancel: () => void;
|
|
80
|
+
}
|
|
81
|
+
export interface DepOptimizationProcessing {
|
|
82
|
+
promise: Promise<void>;
|
|
83
|
+
resolve: () => void;
|
|
84
|
+
}
|
|
85
|
+
export interface OptimizedDepInfo {
|
|
86
|
+
id: string;
|
|
87
|
+
file: string;
|
|
88
|
+
src?: string;
|
|
89
|
+
needsInterop?: boolean;
|
|
90
|
+
browserHash?: string;
|
|
91
|
+
fileHash?: string;
|
|
92
|
+
/**
|
|
93
|
+
* During optimization, ids can still be resolved to their final location
|
|
94
|
+
* but the bundles may not yet be saved to disk
|
|
95
|
+
*/
|
|
96
|
+
processing?: Promise<void>;
|
|
97
|
+
/**
|
|
98
|
+
* ExportData cache, discovered deps will parse the src entry to get exports
|
|
99
|
+
* data used both to define if interop is needed and when pre-bundling
|
|
100
|
+
*/
|
|
101
|
+
exportsData?: Promise<ExportsData>;
|
|
102
|
+
}
|
|
103
|
+
export interface DepOptimizationMetadata {
|
|
104
|
+
/**
|
|
105
|
+
* The main hash is determined by user config and dependency lockfiles.
|
|
106
|
+
* This is checked on server startup to avoid unnecessary re-bundles.
|
|
107
|
+
*/
|
|
108
|
+
hash: string;
|
|
109
|
+
/**
|
|
110
|
+
* The browser hash is determined by the main hash plus additional dependencies
|
|
111
|
+
* discovered at runtime. This is used to invalidate browser requests to
|
|
112
|
+
* optimized deps.
|
|
113
|
+
*/
|
|
114
|
+
browserHash: string;
|
|
115
|
+
/**
|
|
116
|
+
* Metadata for each already optimized dependency
|
|
117
|
+
*/
|
|
118
|
+
optimized: Record<string, OptimizedDepInfo>;
|
|
119
|
+
/**
|
|
120
|
+
* Metadata for non-entry optimized chunks and dynamic imports
|
|
121
|
+
*/
|
|
122
|
+
chunks: Record<string, OptimizedDepInfo>;
|
|
123
|
+
/**
|
|
124
|
+
* Metadata for each newly discovered dependency after processing
|
|
125
|
+
*/
|
|
126
|
+
discovered: Record<string, OptimizedDepInfo>;
|
|
127
|
+
/**
|
|
128
|
+
* OptimizedDepInfo list
|
|
129
|
+
*/
|
|
130
|
+
depInfoList: OptimizedDepInfo[];
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Used by Vite CLI when running `vite optimize`
|
|
134
|
+
*/
|
|
135
|
+
export declare function optimizeDeps(config: ResolvedConfig, force?: boolean | undefined, asCommand?: boolean): Promise<DepOptimizationMetadata>;
|
|
136
|
+
export declare function createOptimizedDepsMetadata(config: ResolvedConfig, timestamp?: string): DepOptimizationMetadata;
|
|
137
|
+
export declare function addOptimizedDepInfo(metadata: DepOptimizationMetadata, type: 'optimized' | 'discovered' | 'chunks', depInfo: OptimizedDepInfo): OptimizedDepInfo;
|
|
138
|
+
/**
|
|
139
|
+
* Creates the initial dep optimization metadata, loading it from the deps cache
|
|
140
|
+
* if it exists and pre-bundling isn't forced
|
|
141
|
+
*/
|
|
142
|
+
export declare function loadCachedDepOptimizationMetadata(config: ResolvedConfig, force?: boolean | undefined, asCommand?: boolean): DepOptimizationMetadata | undefined;
|
|
143
|
+
/**
|
|
144
|
+
* Initial optimizeDeps at server start. Perform a fast scan using esbuild to
|
|
145
|
+
* find deps to pre-bundle and include user hard-coded dependencies
|
|
146
|
+
*/
|
|
147
|
+
export declare function discoverProjectDependencies(config: ResolvedConfig, timestamp?: string): Promise<Record<string, OptimizedDepInfo>>;
|
|
148
|
+
export declare function depsLogString(qualifiedIds: string[]): string;
|
|
149
|
+
/**
|
|
150
|
+
* Internally, Vite uses this function to prepare a optimizeDeps run. When Vite starts, we can get
|
|
151
|
+
* the metadata and start the server without waiting for the optimizeDeps processing to be completed
|
|
152
|
+
*/
|
|
153
|
+
export declare function runOptimizeDeps(config: ResolvedConfig, depsInfo: Record<string, OptimizedDepInfo>): Promise<DepOptimizationResult>;
|
|
154
|
+
export declare function findKnownImports(config: ResolvedConfig): Promise<string[]>;
|
|
155
|
+
export declare function newDepOptimizationProcessing(): DepOptimizationProcessing;
|
|
156
|
+
export declare function depsFromOptimizedDepInfo(depsInfo: Record<string, OptimizedDepInfo>): {
|
|
157
|
+
[k: string]: string;
|
|
158
|
+
};
|
|
159
|
+
export declare function getOptimizedDepPath(id: string, config: ResolvedConfig): string;
|
|
160
|
+
export declare function getDepsCacheDir(config: ResolvedConfig): string;
|
|
161
|
+
export declare function isOptimizedDepFile(id: string, config: ResolvedConfig): boolean;
|
|
162
|
+
export declare function createIsOptimizedDepUrl(config: ResolvedConfig): (url: string) => boolean;
|
|
163
|
+
export declare function extractExportsData(filePath: string, config: ResolvedConfig): Promise<ExportsData>;
|
|
164
|
+
export declare function getDepHash(config: ResolvedConfig): string;
|
|
165
|
+
export declare function optimizedDepInfoFromId(metadata: DepOptimizationMetadata, id: string): OptimizedDepInfo | undefined;
|
|
166
|
+
export declare function optimizedDepInfoFromFile(metadata: DepOptimizationMetadata, file: string): OptimizedDepInfo | undefined;
|
|
167
|
+
export declare function optimizedDepNeedsInterop(metadata: DepOptimizationMetadata, file: string, config: ResolvedConfig): Promise<boolean | undefined>;
|
|
@@ -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;
|