vite 3.0.0-alpha.1 → 3.0.0-alpha.10

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.
@@ -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 {
@@ -534,6 +533,13 @@ export declare interface DepOptimizationOptions {
534
533
  * vite project root. This will overwrite default entries inference.
535
534
  */
536
535
  entries?: string | string[];
536
+ /**
537
+ * Enable esbuild based scan phase, to get back to the optimized deps discovery
538
+ * strategy used in Vite v2
539
+ * @default false
540
+ * @experimental
541
+ */
542
+ devScan?: boolean;
537
543
  /**
538
544
  * Force optimize listed dependencies (must be resolvable import paths,
539
545
  * cannot be globs).
@@ -544,6 +550,12 @@ export declare interface DepOptimizationOptions {
544
550
  * cannot be globs).
545
551
  */
546
552
  exclude?: string[];
553
+ /**
554
+ * Force ESM interop when importing for these dependencies. Some legacy
555
+ * packages advertise themselves as ESM but use `require` internally
556
+ * @experimental
557
+ */
558
+ needsInterop?: string[];
547
559
  /**
548
560
  * Options to pass to esbuild during the dep scanning and optimization
549
561
  *
@@ -567,11 +579,13 @@ export declare interface DepOptimizationOptions {
567
579
  */
568
580
  extensions?: string[];
569
581
  /**
570
- * Disables dependencies optimizations
582
+ * Disables dependencies optimizations, true disables the optimizer during
583
+ * build and dev. Pass 'build' or 'dev' to only disable the optimizer in
584
+ * one of the modes. Deps optimization is enabled by default in both
571
585
  * @default false
572
586
  * @experimental
573
587
  */
574
- disabled?: boolean;
588
+ disabled?: boolean | 'build' | 'dev';
575
589
  }
576
590
 
577
591
  export declare interface DepOptimizationProcessing {
@@ -590,6 +604,20 @@ export declare interface DepOptimizationResult {
590
604
  cancel: () => void;
591
605
  }
592
606
 
607
+ export declare interface DepsOptimizer {
608
+ metadata: DepOptimizationMetadata;
609
+ scanProcessing?: Promise<void>;
610
+ registerMissingImport: (id: string, resolved: string) => OptimizedDepInfo;
611
+ run: () => void;
612
+ isOptimizedDepFile: (id: string) => boolean;
613
+ isOptimizedDepUrl: (url: string) => boolean;
614
+ getOptimizedDepId: (depInfo: OptimizedDepInfo) => string;
615
+ delayDepsOptimizerUntil: (id: string, done: () => Promise<any>) => void;
616
+ registerWorkersSource: (id: string) => void;
617
+ resetRegisteredIds: () => void;
618
+ options: DepOptimizationOptions;
619
+ }
620
+
593
621
  export declare interface ErrorPayload {
594
622
  type: 'error'
595
623
  err: {
@@ -630,6 +658,14 @@ export declare interface ExperimentalOptions {
630
658
  importGlobRestoreExtension?: boolean;
631
659
  }
632
660
 
661
+ export declare type ExportsData = {
662
+ hasImports: boolean;
663
+ exports: readonly string[];
664
+ facade: boolean;
665
+ hasReExports?: boolean;
666
+ jsxLoader?: boolean;
667
+ };
668
+
633
669
  export declare interface FileSystemServeOptions {
634
670
  /**
635
671
  * Strictly restrict file accessing outside of allowing paths.
@@ -657,7 +693,7 @@ export declare interface FileSystemServeOptions {
657
693
  deny?: string[];
658
694
  }
659
695
 
660
- export declare function formatPostcssSourceMap(rawMap: ExistingRawSourceMap, file: string): ExistingRawSourceMap;
696
+ export declare function formatPostcssSourceMap(rawMap: ExistingRawSourceMap, file: string): Promise<ExistingRawSourceMap>;
661
697
 
662
698
  export declare class FSWatcher extends EventEmitter implements fs.FSWatcher {
663
699
  options: WatchOptions
@@ -1131,8 +1167,12 @@ export declare interface InternalResolveOptions extends ResolveOptions {
1131
1167
  isFromTsImporter?: boolean;
1132
1168
  tryEsmOnly?: boolean;
1133
1169
  scan?: boolean;
1170
+ getDepsOptimizer?: () => DepsOptimizer | undefined;
1171
+ shouldExternalize?: (id: string) => boolean | undefined;
1134
1172
  }
1135
1173
 
1174
+ export declare function isDepsOptimizerEnabled(config: ResolvedConfig): boolean;
1175
+
1136
1176
  export declare interface JsonOptions {
1137
1177
  /**
1138
1178
  * Generate a named export for every property of the JSON object
@@ -1150,15 +1190,31 @@ export declare interface JsonOptions {
1150
1190
  export declare interface KnownAsTypeMap {
1151
1191
  raw: string
1152
1192
  url: string
1153
- worker: Worker_2<any, any>
1193
+ worker: Worker
1154
1194
  }
1155
1195
 
1156
1196
  export declare type LibraryFormats = 'es' | 'cjs' | 'umd' | 'iife';
1157
1197
 
1158
1198
  export declare interface LibraryOptions {
1199
+ /**
1200
+ * Path of library entry
1201
+ */
1159
1202
  entry: string;
1203
+ /**
1204
+ * The name of the exposed global variable. Required when the `formats` option includes
1205
+ * `umd` or `iife`
1206
+ */
1160
1207
  name?: string;
1208
+ /**
1209
+ * Output bundle formats
1210
+ * @default ['es', 'umd']
1211
+ */
1161
1212
  formats?: LibraryFormats[];
1213
+ /**
1214
+ * The name of the package file output. The default file name is the name option
1215
+ * of the project package.json. It can also be defined as a function taking the
1216
+ * format as an argument.
1217
+ */
1162
1218
  fileName?: string | ((format: ModuleFormat) => string);
1163
1219
  }
1164
1220
 
@@ -1214,6 +1270,8 @@ export declare interface ManifestChunk {
1214
1270
 
1215
1271
  export declare type Matcher = AnymatchPattern | AnymatchPattern[]
1216
1272
 
1273
+ export declare function mergeAlias(a?: AliasOptions, b?: AliasOptions): AliasOptions | undefined;
1274
+
1217
1275
  export declare function mergeConfig(defaults: Record<string, any>, overrides: Record<string, any>, isRoot?: boolean): Record<string, any>;
1218
1276
 
1219
1277
  export declare class ModuleGraph {
@@ -1280,12 +1338,11 @@ export declare interface OptimizedDepInfo {
1280
1338
  * but the bundles may not yet be saved to disk
1281
1339
  */
1282
1340
  processing?: Promise<void>;
1283
- }
1284
-
1285
- export declare interface OptimizedDeps {
1286
- metadata: DepOptimizationMetadata;
1287
- scanProcessing?: Promise<void>;
1288
- registerMissingImport: (id: string, resolved: string) => OptimizedDepInfo;
1341
+ /**
1342
+ * ExportData cache, discovered deps will parse the src entry to get exports
1343
+ * data used both to define if interop is needed and when pre-bundling
1344
+ */
1345
+ exportsData?: Promise<ExportsData>;
1289
1346
  }
1290
1347
 
1291
1348
  /**
@@ -1530,12 +1587,14 @@ export declare type ResolvedConfig = Readonly<Omit<UserConfig, 'plugins' | 'asse
1530
1587
  server: ResolvedServerOptions;
1531
1588
  build: ResolvedBuildOptions;
1532
1589
  preview: ResolvedPreviewOptions;
1590
+ ssr: ResolvedSSROptions | undefined;
1533
1591
  assetsInclude: (file: string) => boolean;
1534
1592
  logger: Logger;
1535
1593
  createResolver: (options?: Partial<InternalResolveOptions>) => ResolveFn;
1536
1594
  optimizeDeps: DepOptimizationOptions;
1537
1595
  /* Excluded from this release type: packageCache */
1538
1596
  worker: ResolveWorkerOptions;
1597
+ spa: boolean;
1539
1598
  }>;
1540
1599
 
1541
1600
  export declare interface ResolvedPreviewOptions extends PreviewOptions {
@@ -1545,6 +1604,11 @@ export declare interface ResolvedServerOptions extends ServerOptions {
1545
1604
  fs: Required<FileSystemServeOptions>;
1546
1605
  }
1547
1606
 
1607
+ export declare interface ResolvedSSROptions extends SSROptions {
1608
+ target: SSRTarget;
1609
+ format: SSRFormat;
1610
+ }
1611
+
1548
1612
  export declare type ResolvedUrl = [
1549
1613
  url: string,
1550
1614
  resolvedId: string,
@@ -1798,10 +1862,6 @@ export declare interface SendOptions {
1798
1862
  export declare type ServerHook = (server: ViteDevServer) => (() => void) | void | Promise<(() => void) | void>;
1799
1863
 
1800
1864
  export declare interface ServerOptions extends CommonServerOptions {
1801
- /**
1802
- * Force dep pre-optimization regardless of whether deps have changed.
1803
- */
1804
- force?: boolean;
1805
1865
  /**
1806
1866
  * Configure HMR-specific options (port, host, path & protocol)
1807
1867
  */
@@ -1851,6 +1911,8 @@ export declare class SplitVendorChunkCache {
1851
1911
 
1852
1912
  export declare function splitVendorChunkPlugin(): Plugin_2;
1853
1913
 
1914
+ export declare type SSRFormat = 'esm' | 'cjs';
1915
+
1854
1916
  export declare interface SSROptions {
1855
1917
  external?: string[];
1856
1918
  noExternal?: string | RegExp | (string | RegExp)[] | true;
@@ -1860,6 +1922,14 @@ export declare interface SSROptions {
1860
1922
  * Default: 'node'
1861
1923
  */
1862
1924
  target?: SSRTarget;
1925
+ /**
1926
+ * Define the format for the ssr build. Since Vite v3 the SSR build generates ESM by default.
1927
+ * `'cjs'` can be selected to generate a CJS build, but it isn't recommended. This option is
1928
+ * left marked as experimental to give users more time to update to ESM. CJS builds requires
1929
+ * complex externalization heuristics that aren't present in the ESM format.
1930
+ * @experimental
1931
+ */
1932
+ format?: SSRFormat;
1863
1933
  }
1864
1934
 
1865
1935
  export declare type SSRTarget = 'node' | 'webworker';
@@ -2143,6 +2213,11 @@ export declare interface UserConfig {
2143
2213
  * Preview specific options, e.g. host, port, https...
2144
2214
  */
2145
2215
  preview?: PreviewOptions;
2216
+ /**
2217
+ * Force dep pre-optimization regardless of whether deps have changed.
2218
+ * @experimental
2219
+ */
2220
+ force?: boolean;
2146
2221
  /**
2147
2222
  * Dep optimization options
2148
2223
  */
@@ -2201,12 +2276,20 @@ export declare interface UserConfig {
2201
2276
  */
2202
2277
  rollupOptions?: Omit<RollupOptions, 'plugins' | 'input' | 'onwarn' | 'preserveEntrySignatures'>;
2203
2278
  };
2279
+ /**
2280
+ * Whether your application is a Single Page Application (SPA). Set to `false`
2281
+ * for other kinds of apps like MPAs.
2282
+ * @default true
2283
+ */
2284
+ spa?: boolean;
2204
2285
  }
2205
2286
 
2206
2287
  export declare type UserConfigExport = UserConfig | Promise<UserConfig> | UserConfigFn;
2207
2288
 
2208
2289
  export declare type UserConfigFn = (env: ConfigEnv) => UserConfig | Promise<UserConfig>;
2209
2290
 
2291
+ export declare const version: string;
2292
+
2210
2293
  export declare interface ViteDevServer {
2211
2294
  /**
2212
2295
  * The resolved vite config object
@@ -2289,7 +2372,6 @@ export declare interface ViteDevServer {
2289
2372
  * @param forceOptimize - force the optimizer to re-bundle, same as --force cli flag
2290
2373
  */
2291
2374
  restart(forceOptimize?: boolean): Promise<void>;
2292
- /* Excluded from this release type: _optimizedDeps */
2293
2375
  /* Excluded from this release type: _importGlobMap */
2294
2376
  /* Excluded from this release type: _ssrExternals */
2295
2377
  /* Excluded from this release type: _restartPromise */
@@ -1,33 +1,34 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var index = require('./chunks/dep-5cb039d6.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, j as createLogger, c as createServer, d as defineConfig, f as formatPostcssSourceMap, i as isDepsOptimizerEnabled, l as loadConfigFromFile, q as loadEnv, g as mergeAlias, m as mergeConfig, n as normalizePath, o as optimizeDeps, p as preview, e as resolveConfig, u as resolveEnvPrefix, a as resolvePackageData, r as resolvePackageEntry, k as searchForWorkspaceRoot, h as send, s as sortUserPlugins, t as transformWithEsbuild } from './chunks/dep-134b43f1.js';
2
+ export { VERSION as version } from './constants.js';
3
+ import 'fs';
4
+ import 'path';
5
+ import 'url';
6
+ import 'perf_hooks';
7
+ import 'module';
8
+ import 'tty';
9
+ import 'esbuild';
10
+ import 'events';
11
+ import 'assert';
12
+ import 'resolve';
13
+ import 'util';
14
+ import 'net';
15
+ import 'http';
16
+ import 'stream';
17
+ import 'os';
18
+ import 'child_process';
19
+ import 'crypto';
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 };