vite 6.0.0-alpha.0 → 6.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.
@@ -632,6 +632,7 @@ interface Logger {
632
632
  interface LogOptions {
633
633
  clear?: boolean;
634
634
  timestamp?: boolean;
635
+ environment?: string;
635
636
  }
636
637
  interface LogErrorOptions extends LogOptions {
637
638
  error?: Error | RollupError | null;
@@ -787,6 +788,29 @@ type CLIShortcut<Server = ViteDevServer | PreviewServer> = {
787
788
  * https://github.com/preactjs/wmr/blob/main/packages/wmr/src/lib/rollup-plugin-container.js
788
789
  */
789
790
 
791
+ interface BoundedPluginContainer {
792
+ options: InputOptions;
793
+ buildStart(options: InputOptions): Promise<void>;
794
+ resolveId(id: string, importer: string | undefined, options?: {
795
+ attributes?: Record<string, string>;
796
+ custom?: CustomPluginOptions;
797
+ skip?: Set<Plugin>;
798
+ isEntry?: boolean;
799
+ }): Promise<PartialResolvedId | null>;
800
+ transform(code: string, id: string, options?: {
801
+ inMap?: SourceDescription['map'];
802
+ }): Promise<{
803
+ code: string;
804
+ map: SourceMap | {
805
+ mappings: '';
806
+ } | null;
807
+ }>;
808
+ load(id: string, options?: {}): Promise<LoadResult | null>;
809
+ watchChange(id: string, change: {
810
+ event: 'create' | 'update' | 'delete';
811
+ }): Promise<void>;
812
+ close(): Promise<void>;
813
+ }
790
814
  interface PluginContainer {
791
815
  options: InputOptions;
792
816
  buildStart(options: InputOptions): Promise<void>;
@@ -1353,9 +1377,11 @@ declare namespace WebSocket {
1353
1377
  }
1354
1378
 
1355
1379
  declare class Environment {
1380
+ #private;
1356
1381
  name: string;
1357
1382
  config: ResolvedConfig;
1358
1383
  options: ResolvedEnvironmentOptions;
1384
+ get plugins(): BoundedPlugin[];
1359
1385
  get logger(): Logger;
1360
1386
  constructor(name: string, config: ResolvedConfig, options?: ResolvedEnvironmentOptions);
1361
1387
  }
@@ -1370,8 +1396,14 @@ interface FetchModuleOptions {
1370
1396
  */
1371
1397
  declare function fetchModule(environment: DevEnvironment, url: string, importer?: string, options?: FetchModuleOptions): Promise<FetchResult>;
1372
1398
 
1399
+ declare class ScanEnvironment extends Environment {
1400
+ mode: "scan";
1401
+ get pluginContainer(): BoundedPluginContainer;
1402
+ init(): Promise<void>;
1403
+ }
1404
+
1373
1405
  type ExportsData = {
1374
- hasImports: boolean;
1406
+ hasModuleSyntax: boolean;
1375
1407
  exports: readonly string[];
1376
1408
  jsxLoader?: boolean;
1377
1409
  };
@@ -1531,11 +1563,6 @@ interface DepOptimizationMetadata {
1531
1563
  */
1532
1564
  depInfoList: OptimizedDepInfo[];
1533
1565
  }
1534
- /**
1535
- * Scan and optimize dependencies within a project.
1536
- * Used by Vite CLI when running `vite optimize`.
1537
- */
1538
- declare function optimizeDeps(environment: Environment, force?: boolean | undefined, asCommand?: boolean): Promise<DepOptimizationMetadata>;
1539
1566
 
1540
1567
  declare class RemoteEnvironmentTransport {
1541
1568
  private readonly options;
@@ -1548,16 +1575,19 @@ declare class RemoteEnvironmentTransport {
1548
1575
 
1549
1576
  interface DevEnvironmentSetup {
1550
1577
  hot?: false | HMRChannel;
1578
+ watcher?: FSWatcher;
1551
1579
  options?: EnvironmentOptions;
1552
1580
  runner?: FetchModuleOptions & {
1553
1581
  transport?: RemoteEnvironmentTransport;
1554
1582
  };
1583
+ depsOptimizer?: DepsOptimizer;
1555
1584
  }
1556
1585
  declare class DevEnvironment extends Environment {
1557
1586
  mode: "dev";
1558
1587
  moduleGraph: EnvironmentModuleGraph;
1559
- server: ViteDevServer;
1588
+ watcher?: FSWatcher;
1560
1589
  depsOptimizer?: DepsOptimizer;
1590
+ get pluginContainer(): BoundedPluginContainer;
1561
1591
  /**
1562
1592
  * HMR channel for this environment. If not provided or disabled,
1563
1593
  * it will be a noop channel that does nothing.
@@ -1566,18 +1596,21 @@ declare class DevEnvironment extends Environment {
1566
1596
  * environment.hot.send({ type: 'full-reload' })
1567
1597
  */
1568
1598
  hot: HMRChannel;
1569
- constructor(server: ViteDevServer, name: string, setup?: {
1570
- hot?: false | HMRChannel;
1571
- options?: EnvironmentOptions;
1572
- runner?: FetchModuleOptions & {
1573
- transport?: RemoteEnvironmentTransport;
1574
- };
1575
- depsOptimizer?: DepsOptimizer;
1576
- });
1599
+ constructor(name: string, config: ResolvedConfig, setup?: DevEnvironmentSetup);
1600
+ init(): Promise<void>;
1577
1601
  fetchModule(id: string, importer?: string): Promise<FetchResult>;
1578
1602
  transformRequest(url: string): Promise<TransformResult | null>;
1579
1603
  warmupRequest(url: string): Promise<void>;
1580
1604
  close(): Promise<void>;
1605
+ /**
1606
+ * Calling `await environment.waitForRequestsIdle(id)` will wait until all static imports
1607
+ * are processed after the first transformRequest call. If called from a load or transform
1608
+ * plugin hook, the id needs to be passed as a parameter to avoid deadlocks.
1609
+ * Calling this function after the first static imports section of the module graph has been
1610
+ * processed will resolve immediately.
1611
+ * @experimental
1612
+ */
1613
+ waitForRequestsIdle(ignoredId?: string): Promise<void>;
1581
1614
  }
1582
1615
 
1583
1616
  interface TransformResult {
@@ -1585,6 +1618,7 @@ interface TransformResult {
1585
1618
  map: SourceMap | {
1586
1619
  mappings: '';
1587
1620
  } | null;
1621
+ ssr?: boolean;
1588
1622
  etag?: string;
1589
1623
  deps?: string[];
1590
1624
  dynamicDeps?: string[];
@@ -2023,11 +2057,12 @@ interface ViteDevServer {
2023
2057
  *
2024
2058
  * Always sends a message to at least a WebSocket client. Any third party can
2025
2059
  * add a channel to the broadcaster to process messages
2026
- * @deprecated use `environments.get(id).hot` instead
2060
+ * @deprecated use `environment.hot` instead
2027
2061
  */
2028
2062
  hot: HMRBroadcaster;
2029
2063
  /**
2030
2064
  * Rollup plugin container that can run plugin hooks on a given file
2065
+ * @deprecated use `environment.pluginContainer` instead
2031
2066
  */
2032
2067
  pluginContainer: PluginContainer;
2033
2068
  /**
@@ -2037,7 +2072,7 @@ interface ViteDevServer {
2037
2072
  /**
2038
2073
  * Module graph that tracks the import relationships, url to file mapping
2039
2074
  * and hmr state.
2040
- * @deprecated use environment module graphs instead
2075
+ * @deprecated use `environment.moduleGraph` instead
2041
2076
  */
2042
2077
  moduleGraph: ModuleGraph;
2043
2078
  /**
@@ -2064,6 +2099,7 @@ interface ViteDevServer {
2064
2099
  transformIndexHtml(url: string, html: string, originalUrl?: string): Promise<string>;
2065
2100
  /**
2066
2101
  * Transform module code into SSR format.
2102
+ * TODO: expose this to any environment?
2067
2103
  */
2068
2104
  ssrTransform(code: string, inMap: SourceMap | {
2069
2105
  mappings: '';
@@ -2124,6 +2160,7 @@ interface ViteDevServer {
2124
2160
  * passed as a parameter to avoid deadlocks. Calling this function after the first
2125
2161
  * static imports section of the module graph has been processed will resolve immediately.
2126
2162
  * @experimental
2163
+ * @deprecated use environment.waitForRequestsIdle()
2127
2164
  */
2128
2165
  waitForRequestsIdle: (ignoredId?: string) => Promise<void>;
2129
2166
  }
@@ -2627,7 +2664,7 @@ interface TerserOptions extends Terser.MinifyOptions {
2627
2664
  maxWorkers?: number;
2628
2665
  }
2629
2666
 
2630
- interface BuildOptions {
2667
+ interface BuildEnvironmentOptions {
2631
2668
  /**
2632
2669
  * Compatibility transform target. The transform is performed with esbuild
2633
2670
  * and the lowest supported target is es2015/es6. Note this only handles
@@ -2770,13 +2807,6 @@ interface BuildOptions {
2770
2807
  * @default false
2771
2808
  */
2772
2809
  manifest?: boolean | string;
2773
- /**
2774
- * Build in library mode. The value should be the global name of the lib in
2775
- * UMD mode. This will produce esm + cjs + umd bundle formats with default
2776
- * configurations that are suitable for distributing libraries.
2777
- * @default false
2778
- */
2779
- lib?: LibraryOptions | false;
2780
2810
  /**
2781
2811
  * Produce SSR oriented build. Note this requires specifying SSR entry via
2782
2812
  * `rollupOptions.input`.
@@ -2822,7 +2852,16 @@ interface BuildOptions {
2822
2852
  /**
2823
2853
  * create the Build Environment instance
2824
2854
  */
2825
- createEnvironment?: (builder: ViteBuilder, name: string) => BuildEnvironment;
2855
+ createEnvironment?: (name: string, config: ResolvedConfig) => Promise<BuildEnvironment> | BuildEnvironment;
2856
+ }
2857
+ interface BuildOptions extends BuildEnvironmentOptions {
2858
+ /**
2859
+ * Build in library mode. The value should be the global name of the lib in
2860
+ * UMD mode. This will produce esm + cjs + umd bundle formats with default
2861
+ * configurations that are suitable for distributing libraries.
2862
+ * @default false
2863
+ */
2864
+ lib?: LibraryOptions | false;
2826
2865
  }
2827
2866
  interface LibraryOptions {
2828
2867
  /**
@@ -2868,6 +2907,9 @@ type ResolveModulePreloadDependenciesFn = (filename: string, deps: string[], con
2868
2907
  hostId: string;
2869
2908
  hostType: 'html' | 'js';
2870
2909
  }) => string[];
2910
+ interface ResolvedBuildEnvironmentOptions extends Required<Omit<BuildEnvironmentOptions, 'polyfillModulePreload'>> {
2911
+ modulePreload: false | ResolvedModulePreloadOptions;
2912
+ }
2871
2913
  interface ResolvedBuildOptions extends Required<Omit<BuildOptions, 'polyfillModulePreload'>> {
2872
2914
  modulePreload: false | ResolvedModulePreloadOptions;
2873
2915
  }
@@ -2887,25 +2929,25 @@ type RenderBuiltAssetUrl = (filename: string, type: {
2887
2929
  } | undefined;
2888
2930
  declare class BuildEnvironment extends Environment {
2889
2931
  mode: "build";
2890
- builder: ViteBuilder;
2891
- constructor(builder: ViteBuilder, name: string, setup?: {
2932
+ constructor(name: string, config: ResolvedConfig, setup?: {
2892
2933
  options?: EnvironmentOptions;
2893
2934
  });
2935
+ init(): Promise<void>;
2894
2936
  }
2895
2937
  interface ViteBuilder {
2896
2938
  environments: Record<string, BuildEnvironment>;
2897
2939
  config: ResolvedConfig;
2898
- buildEnvironments(): Promise<void>;
2940
+ buildApp(): Promise<void>;
2899
2941
  build(environment: BuildEnvironment): Promise<RollupOutput | RollupOutput[] | RollupWatcher>;
2900
2942
  }
2901
2943
  interface BuilderOptions {
2902
- buildEnvironments?: (builder: ViteBuilder, build: (environment: BuildEnvironment) => Promise<void>) => Promise<void>;
2944
+ sharedConfigBuild?: boolean;
2945
+ sharedPlugins?: boolean;
2946
+ entireApp?: boolean;
2947
+ buildApp?: (builder: ViteBuilder) => Promise<void>;
2903
2948
  }
2904
2949
  type ResolvedBuilderOptions = Required<BuilderOptions>;
2905
- interface BuilderInlineConfig extends Omit<InlineConfig, 'plugins'> {
2906
- plugins?: () => PluginOption[];
2907
- }
2908
- declare function createViteBuilder(builderOptions?: BuilderOptions, defaultBuilderInlineConfig?: BuilderInlineConfig): Promise<ViteBuilder>;
2950
+ declare function createBuilder(inlineConfig?: InlineConfig): Promise<ViteBuilder>;
2909
2951
 
2910
2952
  interface ESBuildOptions extends esbuild_TransformOptions {
2911
2953
  include?: string | RegExp | string[] | RegExp[];
@@ -2919,7 +2961,7 @@ interface ESBuildOptions extends esbuild_TransformOptions {
2919
2961
  type ESBuildTransformResult = Omit<esbuild_TransformResult, 'map'> & {
2920
2962
  map: SourceMap;
2921
2963
  };
2922
- declare function transformWithEsbuild(code: string, filename: string, options?: esbuild_TransformOptions, inMap?: object): Promise<ESBuildTransformResult>;
2964
+ declare function transformWithEsbuild(code: string, filename: string, options?: esbuild_TransformOptions, inMap?: object, root?: string, watcher?: any): Promise<ESBuildTransformResult>;
2923
2965
 
2924
2966
  interface FsUtils {
2925
2967
  existsSync: (path: string) => boolean;
@@ -3190,14 +3232,36 @@ type IndexHtmlTransform = IndexHtmlTransformHook | {
3190
3232
  * or a build environment. Plugins can use this.environment.mode === 'dev' to
3191
3233
  * check if they have access to dev specific APIs.
3192
3234
  */
3193
- type PluginEnvironment = DevEnvironment | BuildEnvironment;
3235
+ type PluginEnvironment = DevEnvironment | BuildEnvironment | ScanEnvironment;
3194
3236
  interface PluginContext extends rollup.PluginContext {
3195
3237
  environment?: PluginEnvironment;
3196
3238
  }
3239
+ interface ResolveIdPluginContext extends rollup.PluginContext {
3240
+ environment?: PluginEnvironment;
3241
+ }
3197
3242
  interface TransformPluginContext extends rollup.TransformPluginContext {
3198
3243
  environment?: PluginEnvironment;
3199
3244
  }
3200
- interface Plugin<A = any> extends rollup.Plugin<A> {
3245
+ /**
3246
+ * There are two types of plugins in Vite. App plugins and environment plugins.
3247
+ * Environment Plugins are defined by a constructor function that will be called
3248
+ * once per each environment allowing users to have completely different plugins
3249
+ * for each of them. The constructor gets the resolved environment after the server
3250
+ * and builder has already been created simplifying config access and cache
3251
+ * managementfor for environment specific plugins.
3252
+ * Environment Plugins are closer to regular rollup plugins. They can't define
3253
+ * app level hooks (like config, configResolved, configureServer, etc).
3254
+ */
3255
+ type ModifyFunctionContext<Function_, NewContext> = Function_ extends (this: infer This, ...parameters: infer Arguments) => infer Return ? (this: NewContext, ...parameters: Arguments) => Return : never;
3256
+ type ModifyObjectHookContext<Handler, Object_ extends {
3257
+ handler: Handler;
3258
+ }, NewContext> = Object_ & {
3259
+ handler: ModifyFunctionContext<Handler, NewContext>;
3260
+ };
3261
+ type ModifyHookContext<Hook, NewContext> = Hook extends {
3262
+ handler: infer Handler;
3263
+ } ? ModifyObjectHookContext<Handler, Hook, NewContext> : ModifyFunctionContext<Hook, NewContext>;
3264
+ interface BasePlugin<A = any> extends rollup.Plugin<A> {
3201
3265
  /**
3202
3266
  * Enforce plugin invocation tier similar to webpack loaders. Hooks ordering
3203
3267
  * is still subject to the `order` property in the hook object.
@@ -3212,6 +3276,61 @@ interface Plugin<A = any> extends rollup.Plugin<A> {
3212
3276
  * - vite build post plugins
3213
3277
  */
3214
3278
  enforce?: 'pre' | 'post';
3279
+ /**
3280
+ * Perform custom handling of HMR updates.
3281
+ * The handler receives a context containing changed filename, timestamp, a
3282
+ * list of modules affected by the file change, and the dev server instance.
3283
+ *
3284
+ * - The hook can return a filtered list of modules to narrow down the update.
3285
+ * e.g. for a Vue SFC, we can narrow down the part to update by comparing
3286
+ * the descriptors.
3287
+ *
3288
+ * - The hook can also return an empty array and then perform custom updates
3289
+ * by sending a custom hmr payload via server.hot.send().
3290
+ *
3291
+ * - If the hook doesn't return a value, the hmr update will be performed as
3292
+ * normal.
3293
+ */
3294
+ hotUpdate?: ObjectHook<(this: void, ctx: HotUpdateContext) => Array<EnvironmentModuleNode> | void | Promise<Array<EnvironmentModuleNode> | void>>;
3295
+ /**
3296
+ * extend hooks with ssr flag
3297
+ */
3298
+ resolveId?: ObjectHook<(this: ResolveIdPluginContext, source: string, importer: string | undefined, options: {
3299
+ attributes: Record<string, string>;
3300
+ custom?: CustomPluginOptions;
3301
+ /**
3302
+ * @deprecated use this.environment
3303
+ */
3304
+ ssr?: boolean;
3305
+ isEntry: boolean;
3306
+ }) => Promise<ResolveIdResult> | ResolveIdResult>;
3307
+ load?: ObjectHook<(this: PluginContext, id: string, options?: {
3308
+ /**
3309
+ * @deprecated use this.environment
3310
+ */
3311
+ ssr?: boolean;
3312
+ }) => Promise<LoadResult> | LoadResult>;
3313
+ transform?: ObjectHook<(this: TransformPluginContext, code: string, id: string, options?: {
3314
+ /**
3315
+ * @deprecated use this.environment
3316
+ */
3317
+ ssr?: boolean;
3318
+ }) => Promise<rollup.TransformResult> | rollup.TransformResult>;
3319
+ buildStart?: ModifyHookContext<rollup.Plugin<A>['buildStart'], PluginContext>;
3320
+ generateBundle?: ModifyHookContext<rollup.Plugin<A>['generateBundle'], PluginContext>;
3321
+ renderChunk?: ModifyHookContext<rollup.Plugin<A>['renderChunk'], PluginContext>;
3322
+ }
3323
+ type BoundedPlugin<A = any> = BasePlugin<A>;
3324
+ interface Plugin<A = any> extends BasePlugin<A> {
3325
+ /**
3326
+ * Opt-in this plugin into the shared plugins pipeline.
3327
+ * For backward-compatibility, plugins are re-recreated for each environment
3328
+ * during `vite build --app`
3329
+ * We have an opt-in per plugin, and a general `builder.sharedPlugins`
3330
+ * In a future major, we'll flip the default to be shared by default
3331
+ * @experimental
3332
+ */
3333
+ sharedDuringBuild?: boolean;
3215
3334
  /**
3216
3335
  * Apply the plugin only for serve or build, or on certain conditions.
3217
3336
  */
@@ -3282,51 +3401,19 @@ interface Plugin<A = any> extends rollup.Plugin<A> {
3282
3401
  * with the mixed client and ssr moduleGraph. Use hotUpdate instead
3283
3402
  */
3284
3403
  handleHotUpdate?: ObjectHook<(this: void, ctx: HmrContext) => Array<ModuleNode> | void | Promise<Array<ModuleNode> | void>>;
3285
- /**
3286
- * Perform custom handling of HMR updates.
3287
- * The handler receives a context containing changed filename, timestamp, a
3288
- * list of modules affected by the file change, and the dev server instance.
3289
- *
3290
- * - The hook can return a filtered list of modules to narrow down the update.
3291
- * e.g. for a Vue SFC, we can narrow down the part to update by comparing
3292
- * the descriptors.
3293
- *
3294
- * - The hook can also return an empty array and then perform custom updates
3295
- * by sending a custom hmr payload via server.hot.send().
3296
- *
3297
- * - If the hook doesn't return a value, the hmr update will be performed as
3298
- * normal.
3299
- */
3300
- hotUpdate?: ObjectHook<(this: void, ctx: HotUpdateContext) => Array<EnvironmentModuleNode> | void | Promise<Array<EnvironmentModuleNode> | void>>;
3301
- /**
3302
- * extend hooks with ssr flag
3303
- */
3304
- resolveId?: ObjectHook<(this: PluginContext, source: string, importer: string | undefined, options: {
3305
- attributes: Record<string, string>;
3306
- custom?: CustomPluginOptions;
3307
- /**
3308
- * @deprecated use this.environment
3309
- */
3310
- ssr?: boolean;
3311
- isEntry: boolean;
3312
- }) => Promise<ResolveIdResult> | ResolveIdResult>;
3313
- load?: ObjectHook<(this: PluginContext, id: string, options?: {
3314
- /**
3315
- * @deprecated use this.environment
3316
- */
3317
- ssr?: boolean;
3318
- }) => Promise<LoadResult> | LoadResult>;
3319
- transform?: ObjectHook<(this: TransformPluginContext, code: string, id: string, options?: {
3320
- /**
3321
- * @deprecated use this.environment
3322
- */
3323
- ssr?: boolean;
3324
- }) => Promise<rollup.TransformResult> | rollup.TransformResult>;
3325
3404
  }
3326
3405
  type HookHandler<T> = T extends ObjectHook<infer H> ? H : T;
3327
3406
  type PluginWithRequiredHook<K extends keyof Plugin> = Plugin & {
3328
3407
  [P in K]: NonNullable<Plugin[P]>;
3329
3408
  };
3409
+ type BoundedPluginConstructor = {
3410
+ (environment: PluginEnvironment): BoundedPluginOption;
3411
+ sharedDuringBuild?: boolean;
3412
+ };
3413
+ type MaybeBoundedPlugin = BoundedPlugin | false | null | undefined;
3414
+ type BoundedPluginOption = MaybeBoundedPlugin | BoundedPluginOption[] | Promise<MaybeBoundedPlugin | BoundedPluginOption[]>;
3415
+ type MaybePlugin = Plugin | BoundedPluginConstructor | false | null | undefined;
3416
+ type PluginOption = MaybePlugin | PluginOption[] | Promise<MaybePlugin | PluginOption[]>;
3330
3417
 
3331
3418
  interface JsonOptions {
3332
3419
  /**
@@ -3438,17 +3525,14 @@ declare function defineConfig(config: UserConfig): UserConfig;
3438
3525
  declare function defineConfig(config: Promise<UserConfig>): Promise<UserConfig>;
3439
3526
  declare function defineConfig(config: UserConfigFnObject): UserConfigFnObject;
3440
3527
  declare function defineConfig(config: UserConfigExport): UserConfigExport;
3441
- type PluginOption = Plugin | false | null | undefined | PluginOption[] | Promise<Plugin | false | null | undefined | PluginOption[]>;
3442
- interface DevOptions {
3528
+ interface DevEnvironmentOptions {
3443
3529
  /**
3444
- * The files to be pre-transformed. Supports glob patterns.
3530
+ * Files tßo be pre-transformed. Supports glob patterns.
3445
3531
  */
3446
- warmup?: {
3447
- files: string[];
3448
- };
3532
+ warmup?: string[];
3449
3533
  /**
3450
3534
  * Pre-transform known direct imports
3451
- * @default true
3535
+ * defaults to true for the client environment, false for the rest
3452
3536
  */
3453
3537
  preTransformRequests?: boolean;
3454
3538
  /**
@@ -3476,10 +3560,23 @@ interface DevOptions {
3476
3560
  /**
3477
3561
  * create the Dev Environment instance
3478
3562
  */
3479
- createEnvironment?: (server: ViteDevServer, name: string) => DevEnvironment;
3563
+ createEnvironment?: (name: string, config: ResolvedConfig) => Promise<DevEnvironment> | DevEnvironment;
3564
+ /**
3565
+ * For environments that support a full-reload, like the client, we can short-circuit when
3566
+ * restarting the server throwing early to stop processing current files. We avoided this for
3567
+ * SSR requests. Maybe this is no longer needed.
3568
+ * @experimental
3569
+ */
3570
+ recoverable?: boolean;
3571
+ /**
3572
+ * For environments associated with a module runner.
3573
+ * By default it is true for the client environment and false for non-client environments.
3574
+ * This option can also be used instead of the removed config.experimental.skipSsrTransform.
3575
+ */
3576
+ moduleRunnerTransform?: boolean;
3480
3577
  }
3481
- type ResolvedDevOptions = Required<Omit<DevOptions, 'createEnvironment'>> & {
3482
- createEnvironment: ((server: ViteDevServer, name: string) => DevEnvironment) | undefined;
3578
+ type ResolvedDevEnvironmentOptions = Required<Omit<DevEnvironmentOptions, 'createEnvironment'>> & {
3579
+ createEnvironment: ((name: string, config: ResolvedConfig) => Promise<DevEnvironment> | DevEnvironment) | undefined;
3483
3580
  };
3484
3581
  type EnvironmentResolveOptions = ResolveOptions & {
3485
3582
  alias?: AliasOptions;
@@ -3495,26 +3592,36 @@ interface SharedEnvironmentOptions {
3495
3592
  */
3496
3593
  nodeCompatible?: boolean;
3497
3594
  webCompatible?: boolean;
3595
+ /**
3596
+ * Should Vite inject timestamp if module is invalidated
3597
+ * Disabling this will break built-in HMR support
3598
+ * @experimental
3599
+ * @default true
3600
+ */
3601
+ injectInvalidationTimestamp?: boolean;
3498
3602
  }
3499
3603
  interface EnvironmentOptions extends SharedEnvironmentOptions {
3500
3604
  /**
3501
3605
  * Dev specific options
3502
3606
  */
3503
- dev?: DevOptions;
3607
+ dev?: DevEnvironmentOptions;
3504
3608
  /**
3505
3609
  * Build specific options
3506
3610
  */
3507
- build?: BuildOptions;
3611
+ build?: BuildEnvironmentOptions;
3508
3612
  }
3509
3613
  type ResolvedEnvironmentResolveOptions = Required<EnvironmentResolveOptions>;
3510
3614
  type ResolvedEnvironmentOptions = {
3511
3615
  resolve: ResolvedEnvironmentResolveOptions;
3512
3616
  nodeCompatible: boolean;
3513
3617
  webCompatible: boolean;
3514
- dev: ResolvedDevOptions;
3515
- build: ResolvedBuildOptions;
3618
+ injectInvalidationTimestamp: boolean;
3619
+ dev: ResolvedDevEnvironmentOptions;
3620
+ build: ResolvedBuildEnvironmentOptions;
3621
+ };
3622
+ type DefaultEnvironmentOptions = Omit<EnvironmentOptions, 'build' | 'nodeCompatible' | 'webCompatible'> & {
3623
+ build?: BuildOptions;
3516
3624
  };
3517
- type DefaultEnvironmentOptions = Omit<EnvironmentOptions, 'nodeCompatible' | 'webCompatible'>;
3518
3625
  interface UserConfig extends DefaultEnvironmentOptions {
3519
3626
  /**
3520
3627
  * Project root directory. Can be an absolute path, or a path relative from
@@ -3727,7 +3834,10 @@ interface LegacyOptions {
3727
3834
  }
3728
3835
  interface ResolvedWorkerOptions {
3729
3836
  format: 'es' | 'iife';
3730
- plugins: (bundleChain: string[]) => Promise<Plugin[]>;
3837
+ plugins: (bundleChain: string[]) => Promise<{
3838
+ plugins: Plugin[];
3839
+ config: ResolvedConfig;
3840
+ }>;
3731
3841
  rollupOptions: RollupOptions;
3732
3842
  }
3733
3843
  interface InlineConfig extends UserConfig {
@@ -3752,10 +3862,11 @@ type ResolvedConfig = Readonly<Omit<UserConfig, 'plugins' | 'css' | 'assetsInclu
3752
3862
  alias: Alias[];
3753
3863
  };
3754
3864
  plugins: readonly Plugin[];
3865
+ rawPlugins: readonly (Plugin | BoundedPluginConstructor)[];
3755
3866
  css: ResolvedCSSOptions;
3756
3867
  esbuild: ESBuildOptions | false;
3757
3868
  server: ResolvedServerOptions;
3758
- dev: ResolvedDevOptions;
3869
+ dev: ResolvedDevEnvironmentOptions;
3759
3870
  builder: ResolvedBuilderOptions;
3760
3871
  build: ResolvedBuildOptions;
3761
3872
  preview: ResolvedPreviewOptions;
@@ -3774,7 +3885,7 @@ interface PluginHookUtils {
3774
3885
  getSortedPluginHooks: <K extends keyof Plugin>(hookName: K) => NonNullable<HookHandler<Plugin[K]>>[];
3775
3886
  }
3776
3887
  type ResolveFn = (id: string, importer?: string, aliasOnly?: boolean, ssr?: boolean) => Promise<string | undefined>;
3777
- declare function resolveConfig(inlineConfig: InlineConfig, command: 'build' | 'serve', defaultMode?: string, defaultNodeEnv?: string, isPreview?: boolean): Promise<ResolvedConfig>;
3888
+ declare function resolveConfig(inlineConfig: InlineConfig, command: 'build' | 'serve', defaultMode?: string, defaultNodeEnv?: string, isPreview?: boolean, patchConfig?: ((config: ResolvedConfig) => void) | undefined, patchPlugins?: ((plugins: (Plugin | BoundedPluginConstructor)[]) => void) | undefined): Promise<ResolvedConfig>;
3778
3889
  declare function sortUserPlugins(plugins: (Plugin | Plugin[])[] | undefined): [Plugin[], Plugin[], Plugin[]];
3779
3890
  declare function loadConfigFromFile(configEnv: ConfigEnv, configFile?: string, configRoot?: string, logLevel?: LogLevel, customLogger?: Logger): Promise<{
3780
3891
  path: string;
@@ -3784,7 +3895,7 @@ declare function loadConfigFromFile(configEnv: ConfigEnv, configFile?: string, c
3784
3895
 
3785
3896
  declare function buildErrorMessage(err: RollupError, args?: string[], includeStack?: boolean): string;
3786
3897
 
3787
- declare function createNodeDevEnvironment(server: ViteDevServer, name: string, options?: DevEnvironmentSetup): DevEnvironment;
3898
+ declare function createNodeDevEnvironment(name: string, config: ResolvedConfig, options?: DevEnvironmentSetup): DevEnvironment;
3788
3899
 
3789
3900
  /**
3790
3901
  * @experimental
@@ -3798,9 +3909,9 @@ interface ServerModuleRunnerOptions extends Omit<ModuleRunnerOptions, 'root' | '
3798
3909
  logger?: ModuleRunnerHmr['logger'];
3799
3910
  };
3800
3911
  /**
3801
- * Provide a custom module runner. This controls how the code is executed.
3912
+ * Provide a custom module evaluator. This controls how the code is executed.
3802
3913
  */
3803
- runner?: ModuleEvaluator;
3914
+ evaluator?: ModuleEvaluator;
3804
3915
  }
3805
3916
  /**
3806
3917
  * Create an instance of the Vite SSR runtime that support HMR.
@@ -3813,11 +3924,11 @@ declare function createServerModuleRunner(environment: DevEnvironment, options?:
3813
3924
  * @experimental
3814
3925
  */
3815
3926
  declare class ServerHMRConnector implements ModuleRunnerHMRConnection {
3816
- private handlers;
3817
3927
  private hmrChannel;
3928
+ private handlers;
3818
3929
  private hmrClient;
3819
3930
  private connected;
3820
- constructor(server: ViteDevServer);
3931
+ constructor(hmrChannel: ServerHMRChannel);
3821
3932
  isReady(): boolean;
3822
3933
  send(message: string): void;
3823
3934
  onUpdate(handler: (payload: HMRPayload) => void): void;
@@ -3874,6 +3985,7 @@ declare function searchForWorkspaceRoot(current: string, root?: string): string;
3874
3985
 
3875
3986
  /**
3876
3987
  * Check if the url is allowed to be served, via the `server.fs` config.
3988
+ * @deprecate use isFileLoadingAllowed
3877
3989
  */
3878
3990
  declare function isFileServingAllowed(url: string, server: ViteDevServer): boolean;
3879
3991
 
@@ -3893,4 +4005,4 @@ interface ManifestChunk {
3893
4005
  dynamicImports?: string[];
3894
4006
  }
3895
4007
 
3896
- export { type Alias, type AliasOptions, type AnymatchFn, type AnymatchPattern, type AppType, type AwaitWriteFinishOptions, type BindCLIShortcutsOptions, BuildEnvironment, type BuildOptions, type CLIShortcut, type CSSModulesOptions, type CSSOptions, type CommonServerOptions, type ConfigEnv, Connect, type CorsOptions, type CorsOrigin, type DepOptimizationConfig, type DepOptimizationMetadata, type DepOptimizationOptions, DevEnvironment, type DevEnvironmentSetup, type ESBuildOptions, type ESBuildTransformResult, EnvironmentModuleGraph, EnvironmentModuleNode, type ExperimentalOptions, type ExportsData, FSWatcher, type FetchModuleOptions, type FileSystemServeOptions, type FilterPattern, type HMRBroadcaster, type HMRBroadcasterClient, type HMRChannel, type HTMLOptions, type HmrContext, type HmrOptions, type HookHandler, type HotUpdateContext, type HtmlTagDescriptor, HttpProxy, type IndexHtmlTransform, type IndexHtmlTransformContext, type IndexHtmlTransformHook, type IndexHtmlTransformResult, type InlineConfig, type InternalResolveOptions, type JsonOptions, type LegacyOptions, type LibraryFormats, type LibraryOptions, type LightningCSSOptions, type LogErrorOptions, type LogLevel, type LogOptions, type LogType, type Logger, type LoggerOptions, type Manifest, type ManifestChunk, type MapToFunction, type AnymatchMatcher as Matcher, ModuleGraph, ModuleNode, type ModulePreloadOptions, type OptimizedDepInfo, type Plugin, type PluginContainer, type PluginHookUtils, type PluginOption, type PreprocessCSSResult, type PreviewOptions, type PreviewServer, type PreviewServerHook, type ProxyOptions, RemoteEnvironmentTransport, type RenderBuiltAssetUrl, type ResolveFn, type ResolveModulePreloadDependenciesFn, type ResolveOptions, type ResolvedBuildOptions, type ResolvedCSSOptions, type ResolvedConfig, type ResolvedModulePreloadOptions, type ResolvedPreviewOptions, type ResolvedSSROptions, type ResolvedServerOptions, type ResolvedServerUrls, type ResolvedUrl, type ResolvedWorkerOptions, type ResolverFunction, type ResolverObject, type RollupCommonJSOptions, type RollupDynamicImportVarsOptions, type SSROptions, type SSRTarget, type SendOptions, type ServerHMRChannel, ServerHMRConnector, type ServerHook, type ServerModuleRunnerOptions, type ServerOptions, SplitVendorChunkCache, type SsrDepOptimizationOptions, Terser, type TerserOptions, type TransformOptions, type TransformResult, type UserConfig, type UserConfigExport, type UserConfigFn, type UserConfigFnObject, type UserConfigFnPromise, type ViteDevServer, type WatchOptions, WebSocket, WebSocketAlias, type WebSocketClient, type WebSocketCustomListener, WebSocketServer, build, buildErrorMessage, createFilter, createLogger, createNodeDevEnvironment, createServer, createServerModuleRunner, createViteBuilder, defineConfig, fetchModule, formatPostcssSourceMap, isCSSRequest, isFileServingAllowed, loadConfigFromFile, loadEnv, mergeAlias, mergeConfig, normalizePath, optimizeDeps, preprocessCSS, preview, resolveConfig, resolveEnvPrefix, rollupVersion, searchForWorkspaceRoot, send, sortUserPlugins, splitVendorChunk, splitVendorChunkPlugin, transformWithEsbuild, VERSION as version };
4008
+ export { type Alias, type AliasOptions, type AnymatchFn, type AnymatchPattern, type AppType, type AwaitWriteFinishOptions, type BindCLIShortcutsOptions, type BoundedPlugin, type BoundedPluginConstructor, BuildEnvironment, type BuildEnvironmentOptions, type BuildOptions, type BuilderOptions, type CLIShortcut, type CSSModulesOptions, type CSSOptions, type CommonServerOptions, type ConfigEnv, Connect, type CorsOptions, type CorsOrigin, type DepOptimizationConfig, type DepOptimizationMetadata, type DepOptimizationOptions, DevEnvironment, type DevEnvironmentOptions, type DevEnvironmentSetup, type ESBuildOptions, type ESBuildTransformResult, EnvironmentModuleGraph, EnvironmentModuleNode, type ExperimentalOptions, type ExportsData, FSWatcher, type FetchModuleOptions, type FileSystemServeOptions, type FilterPattern, type HMRBroadcaster, type HMRBroadcasterClient, type HMRChannel, type HTMLOptions, type HmrContext, type HmrOptions, type HookHandler, type HotUpdateContext, type HtmlTagDescriptor, HttpProxy, type IndexHtmlTransform, type IndexHtmlTransformContext, type IndexHtmlTransformHook, type IndexHtmlTransformResult, type InlineConfig, type InternalResolveOptions, type JsonOptions, type LegacyOptions, type LibraryFormats, type LibraryOptions, type LightningCSSOptions, type LogErrorOptions, type LogLevel, type LogOptions, type LogType, type Logger, type LoggerOptions, type Manifest, type ManifestChunk, type MapToFunction, type AnymatchMatcher as Matcher, ModuleGraph, ModuleNode, type ModulePreloadOptions, type OptimizedDepInfo, type Plugin, type PluginContainer, type PluginHookUtils, type PluginOption, type PreprocessCSSResult, type PreviewOptions, type PreviewServer, type PreviewServerHook, type ProxyOptions, RemoteEnvironmentTransport, type RenderBuiltAssetUrl, type ResolveFn, type ResolveModulePreloadDependenciesFn, type ResolveOptions, type ResolvedBuildEnvironmentOptions, type ResolvedBuildOptions, type ResolvedCSSOptions, type ResolvedConfig, type ResolvedDevEnvironmentOptions, type ResolvedModulePreloadOptions, type ResolvedPreviewOptions, type ResolvedSSROptions, type ResolvedServerOptions, type ResolvedServerUrls, type ResolvedUrl, type ResolvedWorkerOptions, type ResolverFunction, type ResolverObject, type RollupCommonJSOptions, type RollupDynamicImportVarsOptions, type SSROptions, type SSRTarget, type SendOptions, type ServerHMRChannel, ServerHMRConnector, type ServerHook, type ServerModuleRunnerOptions, type ServerOptions, SplitVendorChunkCache, type SsrDepOptimizationOptions, Terser, type TerserOptions, type TransformOptions, type TransformResult, type UserConfig, type UserConfigExport, type UserConfigFn, type UserConfigFnObject, type UserConfigFnPromise, type ViteBuilder, type ViteDevServer, type WatchOptions, WebSocket, WebSocketAlias, type WebSocketClient, type WebSocketCustomListener, WebSocketServer, build, buildErrorMessage, createBuilder, createFilter, createLogger, createNodeDevEnvironment, createServer, createServerModuleRunner, defineConfig, fetchModule, formatPostcssSourceMap, isCSSRequest, isFileServingAllowed, loadConfigFromFile, loadEnv, mergeAlias, mergeConfig, normalizePath, preprocessCSS, preview, resolveConfig, resolveEnvPrefix, rollupVersion, searchForWorkspaceRoot, send, sortUserPlugins, splitVendorChunk, splitVendorChunkPlugin, transformWithEsbuild, VERSION as version };